Hello,
I'm using Outlook 2013 and trying to make a VBA script that outputs how many messages are in each category for an input date range. I need to be able to use the script on a shared inbox that is added to my personal inbox as an "Additional Mailbox", however right now it will only work on my personal inbox. How would I modify this to output for the shared inbox instead? Also, what would I need to do to make it include the sub-folders of the shared inbox? I've experimented with different methods I've found in past posts, however I'm not experienced enough with VBA scripting to get it working properly. The code I have is below:
It would be particularly useful if I could export this data to Excel and display categories by folders, however if this is difficult I don't want to complicate things further.
Any help or suggestions would be very appreciated!
I'm using Outlook 2013 and trying to make a VBA script that outputs how many messages are in each category for an input date range. I need to be able to use the script on a shared inbox that is added to my personal inbox as an "Additional Mailbox", however right now it will only work on my personal inbox. How would I modify this to output for the shared inbox instead? Also, what would I need to do to make it include the sub-folders of the shared inbox? I've experimented with different methods I've found in past posts, however I'm not experienced enough with VBA scripting to get it working properly. The code I have is below:
Code:
Sub CategoriesEmails()
Dim oFolder As MAPIFolder
Dim oDict As Object
Dim sStartDate As String
Dim sEndDate As String
Dim oItems As Outlook.Items
Dim sStr As String
Dim sMsg As String
On Error Resume Next
Set oFolder = Application.ActiveExplorer.CurrentFolder
Set oDict = CreateObject("Scripting.Dictionary")
sStartDate = InputBox("Type the start date (format MM/DD/YYYY)")
sEndDate = InputBox("Type the end date (format MM/DD/YYYY)")
Set oItems = oFolder.Items.Restrict("[Received] >= '" & sStartDate & "' And [Received] <= '" & sEndDate & "'")
oItems.SetColumns ("Categories")
For Each aitem In oItems
sStr = aitem.Categories
If Not oDict.Exists(sStr) Then
oDict(sStr) = 0
End If
oDict(sStr) = CLng(oDict(sStr)) + 1
Next aitem
sMsg = ""
For Each aKey In oDict.Keys
sMsg = sMsg & aKey & ": " & oDict(aKey) & vbCrLf
Next
MsgBox sMsg
Set oFolder = Nothing
End Sub
It would be particularly useful if I could export this data to Excel and display categories by folders, however if this is difficult I don't want to complicate things further.
Any help or suggestions would be very appreciated!