我有下面显示的代码,它打开一个工作簿并运行相应的宏。通过 excel 运行此脚本可以正常工作,但使用相同代码运行 .vbs 文件不会运行宏。我已尝试双击该文件并使用“cscript.exe LaunchMacro.vbs”通过 cmd 提示符运行它。此外,使用 WScript.Echo 不会打印到我的命令行。我在这里错过了什么吗?
谢谢!
Option Explicit
Sub LaunchMacro()
Dim xlApp, xlBook
Dim oShell: Set oShell = CreateObject("WScript.Shell")
oShell.CurrentDirectory = "H:"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
xlApp.Application.Visible = False
Set xlBook = xlApp.Workbooks.Open("H:\SW Tool Resources\test\tester.xlsm")
MsgBox ("File Opened")
xlApp.DisplayAlerts = False
xlApp.Application.Run ("tester.xlsm!Module3.split")
MsgBox ("Application Should Have Run")
xlBook.Saved = True
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
End Sub