Calling VBA macro from .vbs file throws 800A03EC error

前端 未结 3 2050
失恋的感觉
失恋的感觉 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:19

    You open your vbs-file instead of your excel-file... Also make sure that your function/sub is public. In the example below, I created a Public Sub Check in the module "YourModuleName", which I call from the vbs-file.

    Option Explicit
    
    run_macro
    
    Sub run_macro()
        Dim xl1
        Dim xlBook
        Dim FolderFromPath
        Set xl1 = CreateObject("Excel.application")
    
        FolderFromPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") 
        set xlBook = xl1.Workbooks.Open(FolderFromPath & "Changed_chk.xlsm")
        xl1.Application.run "'" & xlBook.Name & "'!YourModuleName.Check"
        xl1.Application.Quit
    End Sub
    

提交回复
热议问题