Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In MS Outlook VBA, how can I test if a folder is for e-mails?

I want to run through all my Outlook folders and build a Table of e-mails in each. But the code to add columns of e-mail properties to the table, such as:

Set oTable = oFolder.GetTable(sFilter)
oTable.Columns.Add ("SenderName")

fails on folders that don’t hold e-mails, such as the folder Calendar.

I could check if the first item in the folder is an e-mail by checking its class:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

oFolder.Items.Item(1).class = olMail

But that cannot be a valid test because an e-mail folder can contain items that are not e-mails, such as a MeetingItem. If the first item in an e-mail folder happens to be a MeetingItem, then the above test would give a false negative on whether the folder is an e-mail folder.

So how can I test if a folder is an e-mail folder so I can know whether I can add e-mail properties to a table made from it?

>Solution :

You can use the Folder.DefaultItemType property which returns a constant from the OlItemType enumeration indicating the default Outlook item type contained in the folder.

Actually, Outlook folders may contain different type of items – mail, appointment, document, post and etc. The best what you could do is to check the default item type for the folder.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading