我想从共享邮箱中获取特定文件夹中的所有电子邮件。 我知道如何从本地邮箱执行此操作。我试图以类似的方式从SharedMailbox获取电子邮件,并且它曾经工作过一次。下次我每次运行宏时,都会在行上出现错误:
Set folder = folder.Folders(Sub_Folder) in "Shared mailbox" block
错误:运行时错误'-2147221233(8004010f)':自动化错误
Sub GetEmailsFromSharedMailboxFolder()
'Declare Variables
Dim app As Outlook.Application
Dim nameSpace As Outlook.nameSpace
Dim folder As Outlook.MAPIFolder
Dim objOwner As Object
Dim item As Object
Dim i As Integer
Dim Sub_Folder As String
Dim Shared_Mailbox As String
'Input Variables
Sub_Folder = "Very_Important"
Shared_Mailbox = "Giants_Hunters@Fake_Company.com"
'Shared Mailbox block
'Set owner
Set objOwner = nameSpace.CreateRecipient(Shared_Mailbox)
'Set default Folder
Set folder = nameSpace.GetSharedDefaultFolder(objOwner, 6)
'Set subfolder
If Sub_Folder <> "" Then
Set folder = folder.Folders(Sub_Folder)
End If
'Shared Mailbox block
'Save emials subject
i = 1
For Each item In folder.Items
Range("A" & i) = item.Subject
i = i + 1
Next
End Sub
答案 0 :(得分:0)
问题已解决: 我必须打开Outlook->文件->帐户设置->帐户设置... 在“电子邮件”选项卡中,单击“更改”按钮,然后取消选中“使用Chached Exchange模式将电子邮件下载到Outlook数据文件”,然后单击“下一步”。