Thursday, February 6, 2014

Outlook VBA for auto-firing the "message domain" user field for each incoming message

This code goes in the existing ThisOutlookSession

The highlighted portion is the entry point into the MyDomains. All the other code is required to get outlook to pay attention.

--------Code below this line----------------------------

Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
  Dim olApp As Outlook.Application
  Dim objNS As Outlook.NameSpace
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  ' default local Inbox
  Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal item As Object)

  On Error GoTo ErrorHandler
  Dim Msg As Outlook.MailItem
  If TypeName(item) = "MailItem" Then
    Call MyDomains.SetDomainMailObject(item)
  End If
ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.description
  Resume ProgramExit
End Sub

No comments:

Post a Comment