Shared mailbox name: [email protected]
I need:
- to access folders Madhvi and P_Wardah with their four sub folders
- set a date range for report extraction (with the subject, sender, date sent, folder name we are accessing)
- automate to run each week
I am not able to access the second folder and the subfolders
Option Explicit
Sub EmailStatsV3()
Dim Item As Object
Dim varOutput() As Variant
Dim lngcount As Long
Dim xlApp As Excel.Application
Dim xlSht As Excel.Worksheet
Dim ShareInbox As Outlook.MAPIFolder
Dim olNs As Outlook.NameSpace
Dim olRecip As Outlook.Recipient
Dim SubFolder As Object
Set olNs = Application.GetNamespace("MAPI")
Set olRecip = olNs.CreateRecipient("[email protected]") '// Owner's Name or email address
Set ShareInbox = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox)
Set SubFolder = ShareInbox.Folders("P_Wardah")
ReDim varOutput(1 To SubFolder.Items.Count, 1 To 4)
For Each Item In SubFolder.Items
If TypeName(Item) = "MailItem" Then
lngcount = lngcount + 1
varOutput(lngcount, 1) = Item.ReceivedTime 'stats on when received
varOutput(lngcount, 2) = Item.Subject 'to split out prefix
varOutput(lngcount, 3) = Item.Sender
varOutput(lngcount, 4) = SubFolder.Name
End If
Next
'Creates a blank workbook in excel
Set xlApp = New Excel.Application
Set xlSht = xlApp.Workbooks.Add.Sheets(1)
xlSht.Range("A1").Resize(UBound(varOutput, 1), _
UBound(varOutput, 2)).Value = varOutput
xlApp.Visible = True
End Sub
- Received details of only folder P_Wardah
- Need to access the folder of Madhvi
- Need to access the sub folders of P_Wardah and Madhvi which are (Treated, No Perimeter, Follow Up, Pending)
- Need to classify them for a date range of each week