我有一个Outlook项目,可以将选定的电子邮件中的所有附件保存到特定位置。 然后我有Excel工作簿,它包含宏,它检查存储的文件并做一些事情。 我想从Outlook Project调用Excel宏,但我收到错误:
运行时错误' -2147417851(80010105)'方法'运行'对象' _Application'失败
代码,我收到错误的地方是:
Sub CheckRDSFiles()
Dim fso As New FileSystemObject
Dim files As TextStream
Dim strFolderPath As String
Dim exApp As Excel.Application
Dim check_RDS As Workbook
Dim readROW As String
'Create complete folder to save files
strFolderPath = SAVE_TO_FOLDER & Format(Now, "MMMM") & "\" & Format(Date, "yyyy-MM-DD") & "\"
'File that stores files to be processed
Set files = fso.OpenTextFile(strFolderPath & "files.txt", ForReading, True, TristateUseDefault)
'Create excel application and open excel workbook with macro
Set exApp = New Excel.Application
Set check_RDS = exApp.Workbooks.Open(CHECK_RDS_PATH)
exApp.Visible = True
'Reading file
Do Until files.AtEndOfStream
'each line represent path to one file
readROW = files.ReadLine
Debug.Print readROW
'call macro from workbook "gatekeeper.xlsm" in module "Test" with name "test" and with parametres
check_RDS.Application.Run "gatekeeper.xlsm!Test.test", readROW, strFolderPath
Loop
End Sub
错误在线:
check_RDS.Application.Run "gatekeeper.xlsm!Test.test", readROW, strFolderPath
有趣的是,我能够偶尔运行它,但我每次都需要毫无问题地运行它。
当我收到此错误时,我的Excel冻结,我必须使用任务管理器将其关闭。
答案 0 :(得分:0)
尝试使用此代替您错误的行:
check_RDS.Run "'gatekeeper.xlsm'!test", readROW, strFolderPath