Assign a custom form to existing Outlook items

Last reviewed on December 30, 2013

One of my favorite (and free!) little utilities is DocMessageClass as it makes it easy to change the message class on existing items to use a new published form. Unfortunately, it doesn't work with Outlook 2013.

Although not quite as easy to use as DocMessageClass, you can use a macro to make the change in all versions, including Outlook 2013.

Note: these methods work for any Outlook item, not just contacts.

This first macro is based off of a macro provided by Microsoft, intended to be used in a template (see the KB article for detailsif you want to run it from a template.

Sub ChangeContactMessageClass()
  ' Change the following line to your new Message Class
   NewMC = "IPM.Contact.Test"
   Set CurFolder = Application.ActiveExplorer.CurrentFolder
   Set AllItems = CurFolder.Items
   NumItems = CurFolder.Items.count
   ' Loop through all of the items in the folder
   For i = 1 To NumItems
      Set CurItem = AllItems.Item(i)
' Test for a distlist
 If CurItem.Class = olContact Then
      ' Test to see if the Message Class needs to be changed
      If CurItem.MessageClass <> NewMC Then
         ' Change the Message Class
         CurItem.MessageClass = NewMC
         ' Save the changed item
      End If
 End If
   MsgBox "Done."
End Sub

To use the code above with non-contact folders, remove the If CurItem.Class = olContact Then line and the second End If.

Macro alternative to DocMessageClass

This alternative to DocMessageClass was posted by chaplaindoug in Outlook Forums: How to Set Existing Contacts to Custom Form

This macro shows how to use change the message class of Public Folder contacts.

Sub ChangeMessageClass()
UName = Environ("UserName")
Set olNS = Application.GetNamespace("MAPI")
Set ContactsFolder = olNS.Folders("Public Folders - " + UName + "")
Set ContactsFolder = ContactsFolder.Folders("All Public Folders")
Set ContactsFolder = ContactsFolder.Folders("Good News Contacts")
'Set ContactsFolder = olNS.GetDefaultFolder(olFolderContacts
Set ContactItems = ContactsFolder.Items

For Each itm In ContactItems

If itm.MessageClass = "IPM.Contact" Then
itm.MessageClass = "IPM.Contact.Good News Contact"
End If

End Sub

Change message class as item is saved

If you need to change the message class on some items, you can use an ItemAdd macro to change the message class when the new item is saved.

This could be used with an If statement to change the message class according to a value in a field (for example, If = "Canada"), or when a new item is created in such a way that the custom form is not used.

Public WithEvents cItems As Outlook.Items

Public Sub Initialize_handler()
    Set cItems = Application.ActiveExplorer.CurrentFolder.Items 
End Sub

Sub cItems_ItemChange(ByVal Item As Object)
  ' Change the following line to your new Message Class
   NewMC = "IPM.Contact.robert-form"
 If Item.Class = olContact Then
      If Item.MessageClass <> NewMC Then
         Item.MessageClass = NewMC
      End If
 End If
End Sub

More Information

How to update existing items in an Outlook folder to use a new custom form This code works in all versions of Outlook and can be run using Run This Form from the forms designer. However, if you use it on Contacts, it does not detect Distribution lists and turns them into contacts. The first code on the page above uses the same code and adds a check for distribution lists.

Written by

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

If the Post Coment button disappears, press your Tab key.