2016-04-25 1620 views
1

我有一個Outlook項目,將所有附件從選定電子郵件保存到特定位置。 然後我有Excel工作簿,它包含宏,它檢查存儲的文件並做一些事情。 我想調用Excel從Outlook項目宏,但我發現了錯誤:通過Outlook運行Excel宏:運行時錯誤「-2147417851(80010105)'

運行時錯誤 '-2147417851(80010105)' Method對象的 '運行' '_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

嘗試,而不是你示數就行了這一點:

check_RDS.Run "'gatekeeper.xlsm'!test", readROW, strFolderPath

+0

運行時錯誤「438」:對象不支持此屬性或方法 –