[英]How to get emails pulled in from Shared Outlook Mailbox?
I'm trying to pull in all the emails from a shared mailbox we use and I tried the below and its working, but from my main/default inbox only. 我试图从我们使用的共享邮箱中提取所有电子邮件,并且尝试了以下内容及其工作方式,但仅从主/默认收件箱中获取。
I've been trying to get this to work from the shared mailbox and just cant seem to get it working. 我一直在尝试从共享邮箱中使它工作,但似乎无法使其正常工作。 I'm not a VBA expert and pulled this together from other threads so any help would be appreciated :)
我不是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
I tried this as well, but couldn't get it to work: 我也尝试过,但是无法正常工作:
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")
It looks like you need to set your Folder
variable to the shared inbox before searching for olFolderInbox
. 看起来您需要在搜索
olFolderInbox
之前将Folder
变量设置为共享收件箱。
This is what works for me: 这对我有效:
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.