[英]How to get body of the email from a shared folder?
以下代码帮助我从收件箱中的默认文件夹中获取数据,但我想更改我的文件夹,该文件夹是共享文件夹并放置在收藏夹文件夹中
我已经尝试使用sharedDefaultFolder
更改getDefaultFolder
但它不起作用。
Dim olApp As Object
Dim olNs As Object
Dim olFldr As Object
Dim olItms As Object
Dim olMail As Object
Set olApp = OutlookApp()
Set olNs = olApp.GetNamespace("MAPI")
Set olFldr = olNs.GetDefaultFolder(6).Folders("impMail")
Set olItms = olFldr.Items
您的声明“设置 olFldr ...”是否为您提供了正确的文件夹?
您可以使用以下语句检查您的文件夹:
for each myO in olNs.GetDefaultFolder(6).folders : debug.Print myO.name : next
您不能简单地将GetDefaultFolder更改为GetSharedDefaultFolder ,您还必须添加 Recipient 对象文件夹的所有者。
表达式: .GetSharedDefaultFolder(Recipient**, FolderType)
带有电子邮件地址的示例
Option Explicit
Public Sub Example()
Dim olNs As Outlook.NameSpace
Set olNs = Application.GetNamespace("MAPI")
Dim RecipientShareName As Outlook.Recipient
Set RecipientShareName = olNs.CreateRecipient("0m3r@email.com") 'address
RecipientShareName.Resolve
Dim ShareInbox As Outlook.Folder
Set ShareInbox = olNs.GetSharedDefaultFolder(RecipientShareName, _
olFolderInbox) 'Inbox
Dim Items As Outlook.Items
Set Items = ShareInbox.Items
Dim i As Long
Dim Item As Outlook.MailItem
For i = Items.Count To 1 Step -1
If TypeOf Items(i) Is Outlook.MailItem Then
Set Item = Items(i)
Debug.Print Item.Subject '// Print Item to Immediate window
End If
Next
End Sub
或者,如果您仅使用名称,请确保已解析收件人对象
收件人姓名示例
Option Explicit
Public Sub Example()
Dim olNs As Outlook.NameSpace
Set olNs = Application.GetNamespace("MAPI")
Dim RecipientShareName As Outlook.Recipient
Set RecipientShareName = olNs.CreateRecipient("0m3r") 'address
RecipientShareName.Resolve
If Not RecipientShareName.Resolved Then
MsgBox "Error on Recipient Object"
Exit Sub
Else
Dim ShareInbox As Outlook.Folder
Set ShareInbox = olNs.GetSharedDefaultFolder(RecipientShareName, _
olFolderInbox) 'Inbox
End If
Dim Items As Outlook.Items
Set Items = ShareInbox.Items
Dim i As Long
Dim Item As Outlook.MailItem
For i = Items.Count To 1 Step -1
If TypeOf Items(i) Is Outlook.MailItem Then
Set Item = Items(i)
Debug.Print Item.Subject '// Print Item to Immediate window
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.