If you want to know the names of all the sub folders in Outlook Inbox.
Here is the code-
Option Explicit
Dim prnt As String
Sub print_folder_names_and_path_for_all_outlook_subfolder_in_inbox()
'tools->refrence->microsoft outlook
Dim olapp As Outlook.Application
Dim olappns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oFolder As Outlook.MAPIFolder
Set olapp = New Outlook.Application
Set olappns = olapp.GetNamespace("MAPI")
Set oinbox = olappns.GetDefaultFolder(olFolderInbox)
'Set oinbox = oinbox.Folders("Ashish")
For Each oFolder In oinbox.Folders
Call subfolders(oFolder)
Next
End Sub
Private Sub subfolders(oParent As Outlook.MAPIFolder)
Dim oFolder1 As Outlook.MAPIFolder
' you can add it to excel sheet or access table
MsgBox oParent.Name
'to know path
MsgBox oParent.FolderPath
'to know parent folder
MsgBox oParent.Parent
' mail count
MsgBox oParent.Items.Count
'unread mails count
MsgBox oParent.Items.Restrict("[UnRead] = True").Count
If (oParent.Folders.Count > 0) Then
For Each oFolder1 In oParent.Folders
Call subfolders(oFolder1)
Next
End If
End Sub
No comments:
Post a Comment