【发布时间】:2015-10-30 16:29:35
【问题描述】:
Excel 2010 和 SSIS 2012 - 当 Outlook 打开并运行宏时,我收到运行时错误 429 - ActiveX 无法创建对象...当 Outlook 关闭时,宏按预期执行 - 它会下载所有以 Mini Report 开头并以 xlsx 结尾的附件。
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
【问题讨论】: