从Outlook中的共享邮箱中导出邮件时出错

时间:2019-03-20 07:55:22

标签: outlook-vba

  

嗨,

     

我正在使用以下代码从共享邮箱中提取电子邮件以转换为Excel。

Sub getDataFromOutlook()

Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim objOwner As Outlook.Recipient
Dim i As Integer

Set OutlookApp = New Outlook.Application

Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")


Set objOwner = OutlookNamespace.CreateRecipient("ZURDO-Shared.MB-ZURDO- 
FINANCE@hyatt.com")
objOwner.Resolve

If objOwner.Resolved Then

Set Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, 
olFolderInbox).Folders("HOTSTATS")
End If
i = 1

For Each OutlookMail In Folder.Items



If OutlookMail.ReceivedTime >= Range("email_Receipt_Date").Value Then

Range("email_Subject").Offset(i, 0).Value = OutlookMail.Subject
Range("email_Subject").Offset(i, 0).Columns.AutoFit
Range("email_Subject").Offset(i, 0).VerticalAlignment = xlTop
Range("email_Date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("email_Date").Offset(i, 0).Columns.AutoFit
Range("email_Date").Offset(i, 0).VerticalAlignment = xlTop
Range("email_Sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("email_Sender").Offset(i, 0).Columns.AutoFit
Range("email_Sender").Offset(i, 0).VerticalAlignment = xlTop
Range("email_Body").Offset(i, 0).Value = OutlookMail.Body
Range("email_Body").Offset(i, 0).Columns.AutoFit
Range("email_Body").Offset(i, 0).VerticalAlignment = xlTop

i = i + 1
End If
Next OutlookMail

Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing

End Sub
  

但是我在以下区域遇到错误

Set Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, olFolderInbox).Folders("HOTSTATS")
  

运行时错误2147221233(8004010f)

     

有人可以帮忙,因为我不明白为什么会出现此错误?

1 个答案:

答案 0 :(得分:0)

错误为MAPI_E_NOT_FOUND。尝试将该语句分成两部分-一个检索“收件箱”,另一个检索子文件夹。

如果代理收件箱在本地缓存,则Outlook仅同步文件夹,而不同步其子文件夹。您将需要关闭缓存模式,或者使用扩展MAPI或赎回以在线模式打开委托邮箱。