Outlook Selecting a Subfolder in the SharedMailbox using GetSharedDefaultFolder

与世无争的帅哥 提交于 2019-12-23 02:36:54

问题


I am having trouble trying to select a subfolder in SharedMailbox.
I have read a number of resources on GetSharedDefaultFolder.
However, struggling to put it together correctly.
Would be really great if you could help with this.

Sub ListOutlookEmailInfoInExcel()
  Dim olNS As Outlook.NameSpace
  Dim olTaskfolder As Outlook.MAPIFolder
  Dim olTask As Outlook.TaskItem
  Dim olItems As Outlook.Items

  Set o1NS = GetNamespace("MAPI")
  Set o1TaskFolder = o1NS.GetSharedDefaultFolder("Shared Folder 1", _
    olFolderInbox).Folders("admin")
  Set o1Items = o1TaskFolder.Items
End Sub

回答1:


You first resolve the owner as described here http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

"You can use the mailbox owner's display name, alias, or email address when resolving the recipient."

Sub ListOutlookEmailInfoInExcel()

Dim olNS As Outlook.NameSpace
Dim olTaskfolder As Outlook.MAPIFolder
Dim olTask As Outlook.TaskItem
Dim olItems As Outlook.Items

Dim objOwner As Outlook.Recipient

Set olNS = GetNamespace("MAPI")

Set objOwner = olNS.CreateRecipient("Shared Folder 1")
objOwner.Resolve

If objOwner.Resolved Then
    Set olTaskFolder = olNS.GetSharedDefaultFolder(objOwner, _
      olFolderInbox).Folders("admin")
    Set olItems = olTaskFolder.Items
End If

End Sub



回答2:


The GetSharedDefaultFolder method of the Namespace class accepts two parameters: a Recipient object and the FolderType value.

The How to: Display a Shared Calendar of a Recipient article provides the following sample code in C#:

private void DisplayManagerCalendar()
{
    Outlook.AddressEntry addrEntry =
         Application.Session.CurrentUser.AddressEntry;
    if (addrEntry.Type == "EX")
    {
        Outlook.ExchangeUser manager =
        Application.Session.CurrentUser.
            AddressEntry.GetExchangeUser().GetExchangeUserManager();
        if (manager != null)
        {
            Outlook.Recipient recip =
                Application.Session.CreateRecipient(manager.Name);
            if (recip.Resolve())
            {
                try
                {
                    Outlook.Folder folder =
                       Application.Session.GetSharedDefaultFolder(
                          recip, Outlook.OlDefaultFolders.olFolderCalendar)
                       as Outlook.Folder;
                    folder.Display();
                }
                catch
                {
                    MessageBox.Show("Could not open manager's calendar.",
                       "GetSharedDefaultFolder Example",
                       MessageBoxButtons.OK,
                       MessageBoxIcon.Error);
                }
            }
        }
    }
}


来源:https://stackoverflow.com/questions/27851850/outlook-selecting-a-subfolder-in-the-sharedmailbox-using-getshareddefaultfolder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!