引用共享的收件箱帐户

时间:2016-01-22 08:50:44

标签: vba outlook outlook-vba

在共享的收件箱帐户中,如果电子邮件未读,我想运行一个脚本。

我试过了:

Sub UnreadMail()

 Dim myEmail As Object
 Dim myNamespace As Object
 Dim myFolder As Folder

 Set myNamespace = Application.GetNamespace("MAPI")
 Set myFolder = myNamespace.GetDefaultFolder(olFolderInbox)

For Each myEmail In myFolder
 If (myEmail.UnRead) Then
  Call SaveAttachToDisk
 End If
 Next
End Sub

1 个答案:

答案 0 :(得分:0)

你几乎得到它,尝试使用GetSharedDefaultFolder查看MSDN GetSharedDefaultFolder Method

Option Explicit
Sub UnreadMail()
    Dim olNameSpace As Outlook.NameSpace
    Dim olShareName As Outlook.Recipient
    Dim olShareInbox As Outlook.Folder
    Dim olItem As Outlook.MailItem

    Set olNameSpace = Application.GetNamespace("MAPI")
    Set olShareName = olNameSpace.CreateRecipient("Om3r@Email.com") 'address
    Set olShareInbox = olNameSpace.GetSharedDefaultFolder(olShareName, olFolderInbox) 'Inbox


    For Each olItem In olShareInbox.Items
        If (olItem.UnRead) Then
            'Call SaveAttachToDisk
            Debug.Print olItem '// Print UnRead Item to Immediate window
        End If
    Next

End Sub