[英]How to get emails pulled in from Shared Outlook Mailbox?
我試圖從我們使用的共享郵箱中提取所有電子郵件,並且嘗試了以下內容及其工作方式,但僅從主/默認收件箱中獲取。
我一直在嘗試從共享郵箱中使它工作,但似乎無法使其正常工作。 我不是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")
看起來您需要在搜索olFolderInbox
之前將Folder
變量設置為共享收件箱。
這對我有效:
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Outlook.Namespace
Dim targetFolder As Outlook.MAPIFolder
Dim firstFolder As Outlook.MAPIFolder
Dim olMail As Outlook.MailItem
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set firstFolder = OutlookNamespace.Folders("your shared mailbox name")
Set targetFolder = firstFolder.Folders("Inbox")
For spot = 1 To 500
If TypeOf targetFolder.Items(spot) Is MailItem Then
Set olMail = targetFolder.Items(spot)
If olMail.ReceivedTime > .... Then
......
End If
End If
Next
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.