MUKESHY12390
Well-known Member
- Joined
- Sep 18, 2012
- Messages
- 901
- Office Version
- 2013
- 2011
- 2010
- 2007
- Platform
- Windows
Hi,
I'm trying to loop through the mails in particular folder, the code I have written code it works but gives the problem when folder has other items other then simple mail(mailItem).
currently I have 3 things on folder 2mails and 1 meeting invitation, because of meeting invitation I get error. Is there anyway we resolve it.
I'm trying to loop through the mails in particular folder, the code I have written code it works but gives the problem when folder has other items other then simple mail(mailItem).
currently I have 3 things on folder 2mails and 1 meeting invitation, because of meeting invitation I get error. Is there anyway we resolve it.
Code:
Sub oAutomail()
Dim oOutlookApp As Outlook.Application
Dim oMail As MailItem '''' it don't produce any error if I change to Object
Dim oNamespace As Outlook.Namespace
Dim oFolder As Outlook.Folder
Dim ofolderlist As Outlook.Folder
Dim oattachement As Attachment
Dim lr
Set oOutlookApp = New Outlook.Application
Set oNamespace = oOutlookApp.GetNamespace("MAPI")
Set oFolder = oNamespace.GetDefaultFolder(olFolderInbox)
'Set ofolder = ofolder.Folders("LivePerson") '' will allow to Direct work through folder
i = 1
For Each ofolderlist In oFolder.Folders '''1st loop through folder
'Debug.Print ofolderlist.Name
If ofolderlist.Name = "Vz" Then
For Each oMail In ofolderlist.Items '''2nd Loop through mail
Debug.Print oMail.Subject
For Each oattachement In oMail.Attachments ''3rd Loop Loop attachments
lr = oattachement.DisplayName ''' attachment Name very importent to save file
Debug.Print lr
' oattachement.SaveAsFile "Z:\Operations\O2\Documents\Transactional\Mukesh\Query Wise\DMacro\outlook\" & lr
i = i + 1
Next oattachement
Next oMail
End If
Next ofolderlist
End Sub