运行 Excel 来自 VBScript 下标的宏超出范围

Running Excel Macro from VBScript Subscript out of range

我正在尝试从 vbs 脚本打印一个文件,并且我正在从 运行ge 中获取一个下标。当 运行 from excel.

时,宏效果很好

VBS 脚本是:

   dim xlApp    
    Set xlApp = CreateObject("Excel.Application")   
    xlApp.Application.Run "'C:\Users\jporter8\Documents\dashboard\testing.xlsm'!Module1.print_Test"     
    xlApp.DisplayAlerts = True     
    xlApp.Application.quit  
    set xlApp = Nothing

而 excel 宏是:

Sub print_Test()
     Sheets("two").PrintOut Copies:=1, Collate:=True, IgnorePrintAreas:=False
    MsgBox "Print successful"
End Sub

而我要打印的 sheet 名为 "two"

我发现这个解决方法是打开工作簿,以便 sheet 存在并且不超出范围

dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")

set xlBook = xlApp.Workbooks.open("C:\Users\jporter8\Documents\dashboard\testing.xlsm", 0, true)
xlApp.Run "Module1.print_Test"
xlApp.DisplayAlerts = True
wscript.echo "Printed"
xlBook.Close
xlApp.Quit
set xlApp = Nothing
set xlBook = Nothing
wscript.echo "Finished"
wscript.Quit