Force Outlook Replies into the format of your choice

December 14, 2009JP11 CommentsRate This ArticlenewLinks to this article


    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

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 if you want to learn more about VBA. Keep Reading »

↑ Scroll to top
Previous Post:

Next Post:

11 Response(s) to Force Outlook Replies into the format of your choice ↓

  1. Michael Stokes says:

    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 says:

      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 says:

        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 says:

    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 says:

    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 says:

      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 says:

        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 says:

          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 says:

    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 says:

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

Speak Your Mind

Tell us what you're thinking...

Certain comments (including first-time comments) are subject to moderation and will not appear immediately. Please view the Comment Policy for more information. To post VBA code in your comment, use tags like this: [cc lang='vb']Code goes here[/cc].




Site last updated August 24, 2010 @ 5:56 pm