简体   繁体   中英

Outlook 2013 VBA to check for valid incoming emails

I wrote some VBA code for use in Outlook 2013. When I searched Google, I found a mention that I should always include a "class check" line near the top of my code. Why?

I run this code as part of an Outlook "rule" and only when incoming emails are from a certain email address.

I don't want ANY emails skipped.

That "exit sub" line is skipping emails because CLASS is sometimes 43 and OlItemType is sometimes 0.

What do those numbers mean and why am I getting them?

Sub AutoForwardIfFrom(objMail As Outlook.MailItem)
    ' Ensure we are working with email items only
    If (objMail.Class <> OlItemType.olMailItem) Then Exit Sub  

     ''''''''' My Code here

End Sub

I found a mention that I should always include a "class check" line near the top of my code. Why?

An incoming Outlook item can be represented by an meeting request item, not only mail items. All Outlook items are classified by message classes. The message class for an item is defined by its MessageClass property, and is used to identify the form that should be used to display the item.

See Item Types and Message Classes which lists the message classes and their corresponding forms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM