If you want to run a loop through all the unread emails in a specific folder in Outlook and capture the information like subject, receive date, body,etc .
Here is the code-
Sub browse_all_unread_emails_in_specific_folder()
'declare outlook objects
Dim olapp As Outlook.Application
Dim olappns As Outlook.Namespace
Dim oinbox As Outlook.Folder
Dim oitem As Outlook.MailItem
'set outlook objects
Set olapp = New Outlook.Application
Set olappns = olapp.GetNamespace("MAPI")
Set oinbox = olappns.GetDefaultFolder(olFolderInbox)
'set the specific folder name
Set oinbox = oinbox.Folders("Ashish")
If oinbox.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "NO Unread Email In Inbox"
Exit Sub
End If
For Each oitem In oinbox.Items.Restrict("[UnRead] = True")
' 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
Please do visit Below links to Learn Outlook VBA
ReplyDeletehttp://www.outlookcode.com
http://www.jpsoftwaretech.com/
If you came know any other Site please share with us.