I want to iterate through the files in a given folder in Enterprise Connect to check, if file exists, delete or add files.
I am able to access the folders, but can't iterate through the items:
Sub IterateEnterpriseConnect()
Dim FP As MAPIFolder
Dim folder As MAPIFolder
Set FP = Application.GetNamespace("MAPI").Folders("Enterprise Connect").Folders("FolderName1").Folders("FolderName2").Folders("FolderName3").Folders("FolderName4").Folders("FolderName5")
MsgBox FP.Name
For Each Elem In FP.Items
MsgBox Elem.Name
Next
End Sub
MsgBox. FP.Name returns the expected Name of the selected folder, but while there a numerous pdf-files in the folder FP.Items seems to be empty.
Any idea how i can access or iterate the items in the folder?
Outlook folder does not store files, it stores messages. Even if you have what looks like a file (Outlook opens it when you double click on a message), the folder contains messages with the message class of IPM.Document.<Attachment type>, e.g. "IPM.Document.Acrobat.Document.DC" for PDF files. Take a look at a message with OutlookSpy (I am its author) - click IMessage and/or Item buttons.
Messages like that are represented by the DocumentItem object in the Outlook Object Model. Just like regular messages (MailItem object), they expose Subject property and the Attachments collection.
Dim Attach as Attachment
...
For Each Elem In FP.Items
MsgBox Elem.Subject
For Each Attach in Elem.Attachments
MsgBox Attach.FileName
Next
Next
Please login to join the live discussion.