VBScript运行Excel宏

时间:2017-06-14 18:50:18

标签: excel vba vbscript

我正在尝试运行此脚本

if WScript.Arguments.Count < 1 Then   
WScript.Echo "Drop file on to me to process."   
Wscript.QuitEnd If
Set oExcel = CreateObject("Excel.Application")
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
Set oVBC = oBook.VBProject.VBComponents oVBC.Import("C:\Test\Test.bas") 
oBook.Application.Run "Test" 
WScript.Echo "Done"

Test.bas文件中的宏名称是Test(),文件位于C:\ Test \ Test.bas - 现在我随时尝试将.xlsx文件拖到.vbscript之上我收到一条错误,内容为

  

语法错误
800A03EA
Microsoft VBScript编译错误

在此脚本中需要更改哪些内容才能解决该问题?

1 个答案:

答案 0 :(得分:1)

Wscript.QuitEnd If需要修复

Wscript.Quit End If

Set oVBC = oBook.VBProject.VBComponents oVBC.Import("C:\Test\Test.bas")

Set oVBC = oBook.VBProject.VBComponents oVBC.Import("C:\Test\Test.bas")