2015-10-30 55 views
0

Excel 2010中& SSIS 2012 - 當Outlook打開,宏跑了,我得到一個運行時錯誤429 - 的ActiveX無法創建對象......當Outlook關閉宏執行如預期 - 下來裝載兩個微型報告開始和結束的xlsx所有附件。VBA宏獲得Outlook附件只能當Outlook關閉

SSIS包打開的Excel與宏文件,但隨後返回該ActiveX錯誤。同樣,如果Outlook關閉,SSIS包打開的Excel,運行宏(下載文件),並在我們的共享驅動器的目錄保存它們。

我有什麼編碼的需要的Outlook被關閉?

VBA代碼如下:

Sub GetAttachments() 

Dim olapp As Object 
Dim olmapi As Object 
Dim olmail As Object 
Dim olitem As Object 
Dim lrow As Integer 
Dim olattach As Object 
Dim FileName As String 

Const num As Integer = 6 
Const path As String = "Y:\Wireline Forecast\MiniReport - Production\Mini Report Region Automation\Load Files\" 
Const strFileType As String = "xlsx" 

Set olapp = CreateObject("outlook.application") 
Set olmapi = getnamespace("MAPI") 
Set olmail = olmapi.getdefaultfolder(num) 

If olmail.Items.restrict("[UNREAD]=True").Count = 0 Then 

    MsgBox ("No Unread mails") 

    Else 
     For Each olitem In olmail.Items.restrict("[UNREAD]=True") 
      If olitem.attachments.Count <> 0 Then 
       For Each olattach In olitem.attachments 
        If Left(olattach.FileName, 11) = "Mini Report" And Right(olattach.FileName, 4) = "xlsx" Then 
        FileName = "Y:\Wireline Forecast\MiniReport - Production\Mini Report Region Automation\Load Files\" & olattach.FileName 
        olattach.SaveAsFile FileName 
        End If 
       Next olattach 
      End If 
     Next olitem 
End If 

End Sub 

回答

0

如果Outlook和Excel在不同的安全環境正在運行可能出現這種情況。確保要麼都有,或者都應用與提升的權限(以管理員身份運行)上運行。

+0

IT有它鎖定,所以沒有爲管理員所以這兩個方案應在相同的安全級別運行運行的能力。 – Robdenham

+0

如何Excel和Outlook中啓動? –

0

居然發現了展望被「鎖定」,當它是開放的,以便讓我建一個變通解釋的ActiveX錯誤....我只是補充說,關閉Outlook的腳本任務,以便在下一個腳本任務可以得到附件,然後重新打開Outlook的另一個腳本任務。不是最漂亮或最乾淨的,但它現在工作。