Pages

Showing posts with label Browse through all emails in Sub Folders of Outlook Inbox and extract the information. Show all posts
Showing posts with label Browse through all emails in Sub Folders of Outlook Inbox and extract the information. Show all posts

Tuesday, January 10, 2012

Browse through all emails in Sub Folders of Outlook Inbox and extract the information

If you want to run a loop through all the emails in the sub folders of outlook inbox and capture the information like subject, receive date, body,etc .

Here is the code-


Option Explicit

Dim oitem As Outlook.MailItem
Sub browse_all_emails_in_all_outlook_folders_and_subfolder_in_inbox_excluding_all_emails_in_inbox()
'Refrence -Microsoft-outlook
Dim olapp As Outlook.Application
Dim olappns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oFolder As Outlook.MAPIFolder
'tools->refrence->microsoft outlook
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_go(oFolder)
Next
End Sub
Private Sub subfolders_go(oParent As Outlook.Folder)
Dim oFolder1 As Outlook.MAPIFolder
For Each oitem In oParent.Items
' u can add if condtions to filter the emails etc.
' u can add data it to excel sheet or database table
MsgBox "Mail Subject -> " & oitem.Subject
MsgBox "Sender Email Address -> " & oitem.SenderEmailAddress
MsgBox "Sender Name -> " & oitem.SenderName
MsgBox "Mail Body -> " & oitem.Body
MsgBox "Recived Date -> " & oitem.ReceivedTime
MsgBox oParent.Name
MsgBox oParent.FolderPath
Next
If (oParent.Folders.Count > 0) Then
For Each oFolder1 In oParent.Folders
Call subfolders_go(oFolder1)
Next
End Ifjavascript:void(0)
End Sub