0
我正在使用以下代碼來計算Outlook中每個類別(代碼在Excel中)有多少封電子郵件。但它沒有考慮到任何子文件夾。你能幫我改變pickfolder以選擇任何子文件夾嗎?Outlook VBA Pickfolder命令以包含子文件夾
Sub test()
Dim oDict As Scripting.Dictionary
Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim olItem As Object
Dim arrData() As Variant
Dim CategoryCnt As Integer
Dim c As Long
On Error Resume Next
Set oDict = New Scripting.Dictionary
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set olFolder = olNs.Session.PickFolder()
'Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
CategoryCnt = olNs.Categories.Count
ReDim arrData(1 To 2, 1 To CategoryCnt)
c = 0
For Each olItem In olFolder.Items
If Not oDict.Exists(olItem.Categories) Then
c = c + 1
arrData(1, c) = olItem.Categories
arrData(2, c) = 1
oDict.Add olItem.Categories, c
Else
arrData(2, oDict.Item(olItem.Categories)) = arrData(2, oDict.Item(olItem.Categories)) + 1
End If
Next olItem
ReDim Preserve arrData(1 To 2, 1 To c)
Range("A2").Resize(UBound(arrData, 2), UBound(arrData, 1)).Value = Application.Transpose(arrData)
MsgBox ("Done")
End Sub
乾杯,
感謝@ newjenn它看起來像你在olParentFolder後我的權利,但它不是輸出,因爲我需要它。例如,Outlook中的每個類別都是誰工作的,並輸出到Excel中,每個類別的總數。給下面類似的東西? \t 史蒂夫約翰菲爾斯圖\t 1個 –
謝謝,但我仍然認爲我們是在兩個不同的軌道在這裏......我說的類別,在Excel的顏色類別,我不太明白你用folderA&folderB得到什麼? –