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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27851850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:45:47  来源:igfitidea点击:

Outlook Selecting a Subfolder in the SharedMailbox using GetSharedDefaultFolder

vbaoutlookoutlook-vba

提问by ArsedianIvan

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.

我在尝试在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

采纳答案by niton

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

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

回答by Eugene Astafiev

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

Namespace 类的GetSharedDefaultFolder方法接受两个参数:Recipient 对象和 FolderType 值。

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

如何显示收件人的共享日历文章提供了在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);
                }
            }
        }
    }
}