您有一个我想要执行以下操作的Word文档中的宏(我们称之为宏A):
除了第2部分 - 运行宏之外,我已经成功地完成了所有工作。请帮忙!!!
这是我到目前为止所做的:
Public Sub Monthly_Commission_Extract()
On Error GoTo ErrHandler:
Dim oExcel As Excel.Application
Dim oWB As Excel.Workbook
Dim strFileName As String
Dim SaveAs As String
strFileName = "\\stnlinasshd01\P403759\Hiport Admin\Month End\Monthly Commission Extract\MONTHLY COMMISSION MASTER"
SaveAs1 = "\\stnlinasshd01\P403759\Hiport Admin\Month End\Monthly Commission Extract\2nd Save"
Set oExcel = New Excel.Application
Workbooks.Open FileName:="\\stnlinasshd01\P403759\Hiport Admin\Month End\Monthly Commission Extract\MONTHLY COMMISSION MASTER.xlsm"
oExcel.Visible = True
Application.Run "MONTHLY COMMISSION MASTER.xls!Retrieve_Monthly_Commission_Data()"
ActiveWorkbook.Application.DisplayAlerts = False
ActiveWorkbook.SaveAs SaveAs1, xlOpenXMLWorkbook, CreateBackup:=False
ActiveWorkbook.Application.DisplayAlerts = True
ActiveWorkbook.Close
DoEvents
Exit Sub
ErrHandler:
MsgBox Err.Description, vbCritical, "HELP ME"
End Sub
代码在此行失败:
Application.Run "MONTHLY COMMISSION MASTER.xls!Retrieve_Monthly_Commission_Data()"
答案 0 :(得分:1)
试试这个:
oExcel.Run "'MONTHLY COMMISSION MASTER.xlsm'!Retrieve_Monthly_Commission_Data"
或者更好的是,像这样使用Set
:
Dim oWB As Excel.Workbook
Set oWB = oExcel.Workbooks.Open(Filename:="\\stnlinasshd01\P403759\Hiport Admin\Month End\Monthly Commission Extract\MONTHLY COMMISSION MASTER.xlsm")
oExcel.Visible = True
oExcel.Run "'" & oWB.Name & "'!Retrieve_Monthly_Commission_Data"