Calling VBA macro from .vbs file throws 800A03EC error

前端 未结 3 2055
失恋的感觉
失恋的感觉 2021-01-28 12:39

I\'m trying to run a VBA macro through .VBS file(File name: Check_final.vbs). Here is the code

Option Explicit

run_macro
         


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 13:25

    Try this simple code (UNTESTED)

    Dim oXlApp, oXLWb, sCurPath
    
    Set oXlApp = CreateObject("Excel.application")
    
    sCurPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
    
    Set oXLWb = oXlApp.Workbooks.Open(sCurPath & "Changed_chk.xlsm")
    
    oXlApp.DisplayAlerts = False
    
    oXlApp.Run "Check"
    
    '~~> Close the file here. Save or discard the changes as per your requirement 
    'oXLWb.Close (True)
    'oXLWb.Close (False)
    oXLWb.Close
    oXlApp.Quit
    
    Set oXLWb = Nothing
    Set oXlApp = Nothing
    

    Also where is your macro? In a sheet or in a module? You may want to see THIS

提交回复
热议问题