【问题标题】:How to reference a non-default folder of a shared Mailbox如何引用共享邮箱的非默认文件夹
【发布时间】:2021-05-22 03:06:30
【问题描述】:

我在共享邮箱 (test@outlook.com) 中有以下文件夹结构

  • 收件箱
  • 测试
    • T-SUB-1
    • T-SUB-2
  • 已发送项目
  • 已删除的项目
  • 列表项

我应该如何引用不是 Outlook 的默认文件夹的 TEST 文件夹。我应该如何检查所有 子文件夹 上的邮件以进行 TEST

这是代码,但这返回 NULL

Private Sub CommandButton1_Click()
    Dim ns          As Outlook.Namespace
    Dim olShareName As Outlook.Recipient
    Dim Inbox       As MAPIFolder
    Dim SubFolder   As MAPIFolder
    Dim msg         As Outlook.MailItem
    Dim msgcount    As Integer
    Dim Items As Outlook.Items
    
    Set ns = GetNamespace("MAPI")
    Set olShareName = ns.CreateRecipient("test@outlook.com")
    Set Inbox = ns.GetSharedDefaultFolder(olShareName, olFolderInbox).Folder("TEST")
    Set Items = Inbox.Items 
    msgcount = 0 
    ....```

【问题讨论】:

  • 在 Google 中输入 vba outlook shared mailbox subfolders site:stackoverflow.com 会得到什么?
  • 我尝试了 0m3r 解决方案,但似乎无法正常工作,因为此 TEST 文件夹不是默认收件箱。

标签: excel vba


【解决方案1】:

将文件夹结构想象成家谱树,而不是它在用户界面中的显示方式。

从收件箱到收件箱的父级,再到与收件箱同级的测试文件夹。

Option Explicit

Private Sub CommandButton1_Click()

    ' Reference to Outlook XX.X object library required
    Dim ns As outlook.namespace
    Dim olShareName As outlook.Recipient
    
    Dim Mailbox  As Folder
    Dim Inbox As Folder
    Dim firstLevelFolder As Folder
    Dim secondLevelFolder As Folder
    
    Dim i As Long
        
    Set ns = GetNamespace("MAPI")
    Set olShareName = ns.CreateRecipient("test@outlook.com")
    Set Inbox = ns.GetSharedDefaultFolder(olShareName, olFolderInbox)
    
    Set Mailbox = Inbox.Parent
    
    Set firstLevelFolder = Mailbox.folders("TEST")
    
    Debug.Print "firstLevelFolder.folders.count: " & firstLevelFolder.folders.count
    
    For i = firstLevelFolder.folders.count To 1 Step -1
        Set secondLevelFolder = firstLevelFolder.folders(i)
        Debug.Print secondLevelFolder.name
    Next
      
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    相关资源
    最近更新 更多