[英]How to get body of the email from a shared folder?
The following code helps me to get data from my default folder in inbox but I want to change my folder which is a shared folder and placed in favorite folders以下代码帮助我从收件箱中的默认文件夹中获取数据,但我想更改我的文件夹,该文件夹是共享文件夹并放置在收藏夹文件夹中
I already tried to change getDefaultFolder
with sharedDefaultFolder
but it doesn't work.我已经尝试使用
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
Does your satement " set olFldr ..." give you the correct folder?您的声明“设置 olFldr ...”是否为您提供了正确的文件夹?
You might check your folders with a statement like:您可以使用以下语句检查您的文件夹:
for each myO in olNs.GetDefaultFolder(6).folders : debug.Print myO.name : next
You cannot simply change GetDefaultFolder to GetSharedDefaultFolder , you have to also add Recipient object The owner of the folder.您不能简单地将GetDefaultFolder更改为GetSharedDefaultFolder ,您还必须添加 Recipient 对象文件夹的所有者。
expression: .GetSharedDefaultFolder(Recipient**, FolderType)
表达式:
.GetSharedDefaultFolder(Recipient**, FolderType)
Example With Email address带有电子邮件地址的示例
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
Or if your using With just Name, then make sure recipient object is resolved或者,如果您仅使用名称,请确保已解析收件人对象
Example with recipient Name收件人姓名示例
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.