Pages

Tuesday, January 10, 2012

Browse through all emails in specific Folder in Outlook and extract the information

If you want to run a loop through all the emails in a specific folder and capture the information like subject, receive date, body,etc . For Example folder Name "Ashish" in below case.

Here is the code-

Sub browse_all_emails_in_specific_folder()
'Refrence-> add-> microsoft outlook
Dim ol As Outlook.Application
Dim olns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oitem As Outlook.MailItem
' set outlook objects
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set oinbox = olns.GetDefaultFolder(olFolderInbox)
'set the specific folder name
Set oinbox = oinbox.Folders("Ashish")
For Each oitem In oinbox.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
Next
End Sub

1 comment:

  1. Please do visit Below links to Learn Outlook VBA
    http://www.outlookcode.com
    http://www.jpsoftwaretech.com/

    If you came know any other Site please share with us.

    ReplyDelete