计算Sharedmailbox中的文件夹和子文件夹

时间:2016-11-01 18:07:43

标签: vba outlook outlook-vba

我想知道我是否可以统计sharedmailbox中的文件夹和子文件夹;

以下是我正在使用的一些代码,但它仅适用于我的默认邮件帐户。 有没有办法修改它以获得文件夹中的子文件夹数量"测试"来自我的共享邮箱名称(AJ47 BOX)

Private Sub CommandButton1_Click()

Dim outapp As Outlook.Application
Set outapp = CreateObject("Outlook.Application")
Dim olNs As Outlook.NameSpace
Set olNs = outapp.GetNamespace("MAPI")
Dim olFolder As Outlook.MAPIFolder


TextBox1 = GetSubFolderCount(olNs.GetDefaultFolder(olFolderInbox).Folders("Tmp"))


End Sub

Private Function GetSubFolderCount(objParentFolder As MAPIFolder) As Long

Dim currentFolders As Folders
Dim fldCurrent As MAPIFolder

Set currentFolders = objParentFolder.Folders
If currentFolders.Count > 0 Then
   Set fldCurrent = currentFolders.GetFirst
   While Not fldCurrent Is Nothing
      TempFolderCount = TempFolderCount + GetSubFolderCount(fldCurrent)
      Set fldCurrent = currentFolders.GetNext
   Wend
   GetSubFolderCount = TempFolderCount + currentFolders.Count
Else
    GetSubFolderCount = 0
End If



End Function

1 个答案:

答案 0 :(得分:1)

使用GetSharedDefaultFolder Method

实施例

Dim olRecip As Recipient
Set olRecip = olNs.CreateRecipient("om3r@email.com")  '// Owner's Name or email address

TextBox1 = GetSubFolderCount(olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("Test"))