How To Force All Plain Text Messages to HTML Format


Last week Katy posted the following request on my Suggestions page.

Do you have a macro or the like to be able to always have it switch to HTML mode when replying to an email? Sometimes it switches to “plain text” (I think when people respond from a blackberry or the like) and I want to be able to always respond in HTML).

While I could create a macro that would convert just those messages she replies to into HTML format, it’s far easier to convert all plain text messages she receives. I checked with Katy to make sure this approach works for her and she says it does.

The code for doing this is very brief. Here’s how it works. Each time Outlook receives items it triggers the NewMailEx event and passes it a list of the EntryIDs (a unique ID identifying each item) of the new items. The code traps the event causing it to run each time new items arrive. The first thing it does is convert the list of EntryIDs into an array. It then loops through that array fetching each new item one at a time. For each item, it checks to see if it is an email. If it is, then it checks the item’s format converting it to HTML if it finds it’s in plain text format. Otherwise, it ignores the item and moves on.

Version Support. This code should work in Outlook 2003 and later.

Instructions and Code.

Outlook 2003 and Earlier.

  1. Start Outlook
  2. Press ALT+F11 to open Outlook’s VB editor
  3. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of
  5. Outlook’s VB Editor window
  6. Edit the code as needed. I included comment lines wherever something needs to or can change
  7. Click the diskette icon on the toolbar to save the changes
  8. Close the VB Editor
  9. Click Tools > Macro > Security
  10. Set the Security Level to Medium
  11. Close Outlook
  12. Start Outlook
  13. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.

Outlook 2007.

  1. Start Outlook
  2. Press ALT+F11 to open Outlook’s VB editor
  3. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  5. Click the diskette icon on the toolbar to save the changes
  6. Close the VB Editor
  7. Click Tools > Trust Center
  8. Click Macro Security
  9. Set Macro Security to “Warnings for all macros”
  10. Click OK
  11. Close Outlook
  12. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.

Outlook 2010.

  1. Start Outlook
  2. Press ALT+F11 to open Outlook’s VB editor
  3. If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
  4. Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
  5. Click the diskette icon on the toolbar to save the changes
  6. Close the VB Editor
  7. Click File and select Options
  8. When the Outlook Options dialog appears click Trust Center then click the Trust Center Settings button
  9. Click Macro Settings
  10. Select either of the two bottom settings (i.e. “Notifications for all macros” or “Enable all macros (not recommended; potentially dangerous code can run)”. The choice of which to choose is up to you. If you select “Notifications”, then you’ll be prompted at times to enable macros. If you pick “Enable all” then there’s a chance that a malicious macro could run. It’s a question of how much risk you want to assume.
  11. Click Ok until the dialog-boxes have all closed
  12. Close Outlook
  13. Start Outlook. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run. Say yes.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim arrEID As Variant, varEID As Variant, olkItm As Object
    arrEID = Split(EntryIDCollection, ",")
    For Each varEID In arrEID
        Set olkItm = Session.GetItemFromID(varEID)
        If olkItm.Class = olMail Then
            If olkItm.BodyFormat = olFormatPlain Then
                olkItm.BodyFormat = olFormatHTML
                olkItm.Save
            End If
        End If
    Next
    Set olkItm = Nothing
End Sub
Advertisements

11 comments on “How To Force All Plain Text Messages to HTML Format

  1. Hi David. I would like to convert received messages only if the subject line contains a certain word. Then I want to forward that converted message to a recipient. What is the best way to complete that task?

    • Hi, Tracy.

      This should do it.

      Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
          'On the next line, edit the word to look for in the subject
          Const KEY_WORD = "something"
          'On the next line, edit the address of the person you want to foward messages containing the keyword to
          Const FWD_ADDR = "someone@company.com"
          Dim arrEID As Variant, varEID As Variant, olkItm As Object, olkFwd As Outlook.MailItem
          arrEID = Split(EntryIDCollection, ",")
          For Each varEID In arrEID
              Set olkItm = Session.GetItemFromID(varEID)
              If olkItm.Class = olMail Then
                  If InStr(1, LCase(olkItm.Subject), LCase(KEY_WORD)) > 0 Then
                      If olkItm.BodyFormat = olFormatPlain Then
                          olkItm.BodyFormat = olFormatHTML
                          olkItm.Save
                          Set olkFwd = olkItm.Forward
                          With olkFwd
                              .To = FWD_ADDR
                              .Send
                          End With
                      End If
                  End If
              End If
          Next
          Set olkItm = Nothing
          Set olkFwd = Nothing
      End Sub
      
    • Hi, Michael.

      No, this macro is strictly for converting received messages. It would require a completely different macro to convert outbound messages. There no need for a macro though. Outlook allows you to choose the format of outbound messages. It’s simpler to set Outlook to send in your chosen format rather than using a macro to convert the messages into some format as they are sent. That being the case, I can’t help but think that I don’t understand the situation. Can you explain a bit more?

  2. Hi, for some reason this macro doesn’t seem to be working in Office 2013 (unlike the attachment list which works fine). Any idea why or what I can do to make it work? I hate plain text emails. 🙂

    • Hi, yes it is. I had it work just fine in office 2010 for a few months but I upgraded to 2013 and now it doesn’t work. Macros are enabled.

    • Andreea,

      Please add this code to the ThisOutlookSession module. Once you’ve done that, please close and restart Outlook. When Outlook starts it should display a dialog-box saying “Macros are enabled”. If it does, then please test the original code by sending yourself a message that’s in plain text format. If that dialog-box does not appear, then macros are not working, which would explain whey the original code isn’t working.

      Private Sub Application_Startup()
          Msgbox "Macros are enabled."
      End Sub
      

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s