未知的运行时错误VB

时间:2017-02-23 12:36:12

标签: excel vba vbscript

我有一个在excel文件中运行宏的VB脚本。 代码运行并正确生成结果文件。

Excel宏运行正常。 VB代码说“未知的运行时错误”后,我收到错误消息。                                      '代码800A9C68'                                      '第8行'第2章'

代码:

Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("Z:\Confidential Restricted\Weekly_HR_Employees_Macro.xlsm", False)

'msgbox("3")

xlApp.Run "Weekly_HR_Employees_Macro.Weekly_HR_Employees_Macro"

'xlbook.Save
'xlBook.Close False
'set xlBook = Nothing

xlApp.Quit
'Set xlApp = Nothing

1 个答案:

答案 0 :(得分:2)

尝试下面的VBScript:

Option Explicit

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

set xlBook = xlApp.Workbooks.Open("Z:\Confidential Restricted\Weekly_HR_Employees_Macro.xlsm",0, False)
xlApp.Run "Weekly_HR_Employees_Macro"
xlBook.Close True
xlApp.Quit

set xlBook = Nothing
Set xlApp = Nothing