【问题标题】:Running Excel Macro from VBScript Subscript out of range从 VBScript 下标运行 Excel 宏超出范围
【发布时间】:2020-07-08 04:05:05
【问题描述】:

我正在尝试从 vbs 脚本打印文件,但下标超出范围。从 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

我要打印的工作表名为“两个”

【问题讨论】:

    标签: excel vba vbscript


    【解决方案1】:

    我找到了这个解决方法来打开工作簿,以便工作表存在并且没有超出范围

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多