如何从“共享Outlook邮箱”中提取电子邮件?

时间:2018-11-09 15:14:24

标签: excel vba email outlook shared

我试图从我们使用的共享邮箱中提取所有电子邮件,并尝试了以下内容及其工作方式,但仅从我的 main / default 收件箱中获取。

我一直试图从共享邮箱中使它工作,但似乎无法使其正常工作。我不是VBA专家,所以将其与其他线程合并在一起,因此可以提供任何帮助:)

Sub GetFromOutlook()

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

Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox)


i = 1

For Each OutlookMail In Folder.Items
    If OutlookMail.ReceivedTime >= Range("From_date").Value Then
        Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
        Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
        Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
        'Range("eMail_Recipients").Offset(i, 0).Value = OutlookMail.Recipients
        Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body

        i = i + 1
    End If
Next OutlookMail

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

End Sub

我也尝试过此方法,但无法使其起作用:

Sub GetFromOutlook()

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


Dim olShareName As Outlook.Recipient


Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set olShareName = OutlookNamespace.CreateRecipient("MailboxName")

Set Folder = OutlookNamespace.GetSharedDefaultFolder(olShareName, olFolderInbox).Folders("Mailbox@XYZ.com").Folders("Inbox")

1 个答案:

答案 0 :(得分:0)

在搜索class MouseInput extends UIEvent { private isMouse: undefined } class KeyboardInput extends UIEvent { private isKeyboard: undefined } 之前,您似乎需要将Folder变量设置为共享收件箱。

这对我有用:

olFolderInbox