Outlook 使用 GetSharedDefaultFolder 在 SharedMailbox 中选择一个子文件夹

Outlook Selecting a Subfolder in the SharedMailbox using GetSharedDefaultFolder

我在尝试 select SharedMailbox 中的子文件夹时遇到问题。
我在 GetSharedDefaultFolder 上阅读了很多资源。
但是,很难将它们正确地组合在一起。
如果您能提供帮助,那就太好了。

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

命名空间 class 的 GetSharedDefaultFolder 方法接受两个参数:Recipient 对象和 FolderType 值。

How to: Display a Shared Calendar of a Recipient 文章提供了以下 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);
                }
            }
        }
    }
}

您首先按照此处所述解析所有者 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