Force Outlook Replies into the format of your choice

In Outlook Tip 434: Change Reply Format, Diane Poremsky writes:

Outlook does not offer a way to always use a specific format for all replies, be it RTF or HTML. You need to either change it on each message or write VBA macro to change the format.

That's what we're here for! OutlookCode has VBA to always reply in HTML format, but sometimes I like to roll my own. In this case, I wrote four different procedures that each do something slightly different.

The first procedure will force replies into HTML or plain text, depending on the current value of the BodyFormat property. If the message is in RTF format, it will downgrade the reply to HTML. Otherwise, it will use the existing format. In short, it's a bit more dynamic (and less disruptive) than blindly forcing all replies to HTML. Consider it a "soft" force away from RTF.

The second procedure does the same thing, except with plain text. If a message is RTF, it replies as plain text, but if the message is HTML, it will reply as HTML.

Soft HTML Reply

Sub HTMLReply()
' assumes Outlook 2003 and internal msg editor

' if msg is RTF, convert it to HTML, but
' if msg is already in HTML or plain text, reply using same format

  On Error GoTo ErrorHandler

  Dim msg As Outlook.MailItem
  Dim msgReply As Outlook.MailItem

  Set msg = GetMailItem

  If msg Is Nothing Then
    Call MessageBox("No message selected.")
    GoTo ProgramExit
  End If

  ' if msg is RTF, convert to HTML, else leave it alone
  Select Case msg.BodyFormat
    Case olFormatRichText
      Set msgReply = msg.Reply
      msgReply.BodyFormat = olFormatHTML
      msgReply.Display
    Case Else
      If MessageBox("This message is not in Rich Text Format (RTF)." & _
        " Reply anyway?", vbYesNo) = vbYes Then
        Set msgReply = msg.Reply
        msgReply.Display
      End If
  End Select

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.Description
  Resume ProgramExit
End Sub

Soft Plain Text Reply

Sub PlainTextReply()
' assumes Outlook 2003 and internal msg editor

' if msg is RTF, convert it to HTML, but
' if msg is already in HTML or plain text, reply using same format

  On Error GoTo ErrorHandler

  Dim msg As Outlook.MailItem
  Dim msgReply As Outlook.MailItem

  Set msg = GetMailItem

  If msg Is Nothing Then
    Call MessageBox("No message selected.")
    GoTo ProgramExit
  End If

  ' if msg is RTF, convert to plain text, else leave it alone
  Select Case msg.BodyFormat
    Case olFormatRichText
      Set msgReply = msg.Reply
      msgReply.BodyFormat = olFormatPlain
      msgReply.Display
    Case Else
      If MessageBox("This message is not in Rich Text Format (RTF)." & _
        " Reply anyway?", vbYesNo) = vbYes Then
        Set msgReply = msg.Reply
        msgReply.Display
      End If
  End Select

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.Description
  Resume ProgramExit
End Sub

GetMailItem and MessageBox are functions that, respectively, return a referenced to the currently selected or open mail item and display messageboxes. Visit Meeting Replies in Outlook 2003 for a copy of each.

The next two procedures just force all replies into either HTML or plain text format.

Force all replies to HTML

Sub ForceHTMLReply()
' assumes Outlook 2003 and internal msg editor
' force all replies to HTML

  On Error GoTo ErrorHandler

  Dim msg As Outlook.MailItem
  Dim msgReply As Outlook.MailItem

  Set msg = GetMailItem

  If msg Is Nothing Then
    Call MessageBox("No message selected.")
    GoTo ProgramExit
  End If

  ' if msg is HTML, just reply, else convert all replies to HTML
  Select Case msg.BodyFormat
    Case olFormatHTML
      Set msgReply = msg.Reply
      msgReply.Display
    Case Else
      Set msgReply = msg.Reply
      msgReply.BodyFormat = olFormatHTML
      msgReply.Display
  End Select

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.Description
  Resume ProgramExit
End Sub

Force all replies to plain text

Sub ForcePlainTextReply()
' assumes Outlook 2003 and internal msg editor
' force all replies to plain text

  On Error GoTo ErrorHandler

  Dim msg As Outlook.MailItem
  Dim msgReply As Outlook.MailItem

  Set msg = GetMailItem

  If msg Is Nothing Then
    Call MessageBox("No message selected.")
    GoTo ProgramExit
  End If

  ' if msg is plain text, just reply, else convert
  ' all replies to plain text
  Select Case msg.BodyFormat
    Case olFormatPlain
      Set msgReply = msg.Reply
      msgReply.Display
    Case Else
      Set msgReply = msg.Reply
      msgReply.BodyFormat = olFormatPlain
      msgReply.Display
  End Select

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.number & " - " & Err.Description
  Resume ProgramExit
End Sub

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button

comment bubble 13 Comments:

  1. Michael Stokes writes:

    trying to use the Force all replies to HTML

    Ok, call me stupid but I can't get this code to run. I have tried pasting into the ThisOutlookSession. I have tried creating a ClassModule but don't know how to make run from there. Can someone please point me in the right direction. Thanks

    • JP writes:

      Michael,

      The code goes into a standard module; ThisOutlookSession is usually reserved for event handlers.

      Paste ForceHTMLReply into a standard module. You also need a copy of the GetMailItem function. Visit Meeting Replies in Outlook 2003 for that.

      Then you select or open a message you want to reply to in HTML and run ForceHTMLReply by pressing Alt+F8 and selecting ForceHTMLReply from the resulting dialog box.

      HTH

      • Brian Riley writes:

        This is nice, but the method is very clumsy with regards to Signatures. I found that calling the button command after the message is displayed preserves the presentation better.

        Instead of msgReply.BodyFormat = olFormatPlain
        msgReply.Display

        Try using: msgReply.Display
        ActiveInspector.CommandBars.FindControl(, 5564).Execute

        Button Command: Plain Text = 5563
        HTML = 5564
        Rich Text = 5565

        Also, if you go to http://outlook-tips.net/cs/blogs/outlooktips/archive/2007/08/02/671.aspx, you find the code to automatically Reply/ReplyToAll/Forward any message without calling/creating a seperate Macro button.

        I've modified this code using the FindControl function…

        //begin code//

        Option Explicit
        
        Private WithEvents oExpl As Explorer
        Private WithEvents oItem As MailItem
        
        Private Sub Application_Startup()
        
           Set oExpl = Application.ActiveExplorer
        
        End Sub
        
        Private Sub oExpl_SelectionChange()
        
           On Error Resume Next
           Set oItem = oExpl.Selection.Item(1)
        
        End Sub
        
        Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean)
        
           If bDiscardEvents Or oItem.BodyFormat = olFormat Then
               Exit Sub
           End If
        
           Cancel = True
        
            oItem.Reply.Display
        
            ActiveInspector.CommandBars.FindControl(, 5564).Execute
        
        End Sub
        
        Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean)
        
           If bDiscardEvents Or oItem.BodyFormat = olFormat Then
               Exit Sub
           End If
        
           Cancel = True
        
            oItem.Reply.Display
        
            ActiveInspector.CommandBars.FindControl(, 5564).Execute
        
        End Sub
        
        Private Sub oItem_Forward(ByVal Forward As Object, Cancel As Boolean)
        
           If bDiscardEvents Or oItem.BodyFormat = olFormat Then
               Exit Sub
           End If
        
           Cancel = True
        
            oItem.Reply.Display
        
            ActiveInspector.CommandBars.FindControl(, 5564).Execute
        
        End Sub

        //end code//

        Note: You will need to restart Outlook before these functions become available.

        Hope this helps

  2. JP writes:

    Great code Brian, thanks for sharing! In order to get the signature to work, you'll need to display the email first. Or, you can grab the signature from the hard disk. Or execute the menu control.

  3. Nick writes:

    Hi,

    I have a question slightly off topic but here goes.

    I want to know how to make every single email to be forced to be in HTML.

    If an application uses MAPIMAIL then outlook will open the email in plain text. For example if you right hand click on a file on your desktop and go send to > Mail recipient it will open in plain text.

    Do you know of a way to force outlook to open every new message in HTML?

    I have been trying to find an answer to this for so long.

    Cheers,

    • JP writes:

      Sorry, you can't control every possible way an email can be created and force it to HTML. Just don't use that option if you don't want to send plain text emails.

      • Nick writes:

        The problem is that a program that I have to use with work uses the MAPIMAIL and i can't make it do anything else… Do you know of a way to change the way MAPIMAIL opens an email in outlook? I can't find squat… :(

        • JP writes:

          I prefer plain text emails anyway. Not everyone uses Outlook and some hypersensitive people get annoyed when you send non-plain text emails.

  4. Talal writes:

    Thats a fantastic code given there?Is there a possibility to modify the line spacing like ;lets say to 1.5 while replying to a message?

  5. JP writes:

    In the code that uses HTML replies, you'll need to use the proper HTML syntax to set the line spacing. See http://www.jpsoftwaretech.com/blog/2008/09/send-links-via-outlook-email/ for an example.

  6. Matt writes:

    *sigh* this code works, but NOT for signature. How the EFF do you make it work for signatures?

    • JP writes:

      Try reading the body into a String variable, then setting the .Body property to the value of the string.

Comments on this article are closed. Why?

Site last updated: February 12, 2012