“Always reply using HTML” code sample

May 18, 2011
By

See Outlook's Reply Format for reasons why you shouldn't change the format.

Originally posted as a comment in Tip 434: Change Reply Format August 2007

This code sample was checked (by me) against Outlook 2007 and 2010.  Others report that it works with Outlook 2003.

To switch this code to always use plain text, locate and change this line in the code to comment out the HTML code (2) and remove the comment from plain text format (1). Note that Outlook 2003 and later have the ability to always use plain text.

olFormat = olFormatPlain        '(*1) - always use plain text'olFormat = olFormatHTML        '(*2) - always use HTML

Copy and paste the code from this page into your ThisOutlookSession project. To do this, click in the text box, Select All using Ctrl+A, Ctrl+C to copy.

In Outlook, press Alt+F11 to open the VBA editor and expand Microsoft Outlook Objects then double click on ThisOutlookSession to open it in the editing pane and Ctrl+P to paste the code.

How to use VBA code samples in Outlook

Option Explicit 

Private WithEvents oExpl As Explorer 
Private WithEvents oItem As MailItem 

Private bDiscardEvents As Boolean 
Private olFormat As OlBodyFormat 


Private Sub Application_Startup() 

Set oExpl = Application.ActiveExplorer 

bDiscardEvents = False 

'olFormat = olFormatPlain '(*1) - uz.ywaj zawsze formatu "zwyk?y tekst" 
olFormat = olFormatHTML '(*2) - uz.ywaj zawsze formatu HTML 

End Sub 

Private Sub oExpl_SelectionChange() 

On Error Resume Next 
Set oItem = oExpl.Selection.Item(1) 

End Sub 

' (*3) Uz.ytkownik wybra? polecenie "Odpowiedz" 
Private Sub oItem_Reply(ByVal Response As Object, Cancel As Boolean) 

If bDiscardEvents Or oItem.BodyFormat = olFormat Then 
Exit Sub 
End If 

'(*4) Anuluj domys'lna; akcje; 
Cancel = True 

bDiscardEvents = True 

' (*5) Utwo'rz odpowiedz' na wiadomos'c' w formacie tekstowym 
Dim oResponse As MailItem 
Set oResponse = oItem.Reply 
oResponse.BodyFormat = olFormat 
oResponse.Display 

bDiscardEvents = False 

End Sub 

' (*6) Uz.ytkownik wybra? polecenie "Odpowiedz wszystkim" 
Private Sub oItem_ReplyAll(ByVal Response As Object, Cancel As Boolean) 

If bDiscardEvents Or oItem.BodyFormat = olFormat Then 
Exit Sub 
End If 

Cancel = True 

bDiscardEvents = True 

Dim oResponse As MailItem 
Set oResponse = oItem.ReplyAll 
oResponse.BodyFormat = olFormat 
oResponse.Display 

bDiscardEvents = False 

End Sub 

' (*7) Uz.ytkownik wybra? polecenie "Przes'lij dalej" 
Private Sub oItem_Forward(ByVal Forward As Object, Cancel As Boolean) 

If bDiscardEvents Or oItem.BodyFormat = olFormat Then 
Exit Sub 
End If 

Cancel = True 

bDiscardEvents = True 

Dim oResponse As MailItem 
Set oResponse = oItem.Forward 
oResponse.BodyFormat = olFormat 
oResponse.Display 

bDiscardEvents = False 

End Sub

You can copy and paste from the text box above or download a text file containing the VBA code: http://www.outlook-tips.net/files/always-reply-using-html.txt

Related posts:

Tags: , , ,

« « Get Internet Header code sample for Microsoft Outlook
Remove the To field from an Outlook message form » »

15 Responses to “Always reply using HTML” code sample

  1. Todor on June 2, 2011 at 4:17 am

    tested on 2003?

  2. dianep on June 2, 2011 at 4:53 am

    Yes, according to the comments in the original post, it does work in Outlook 2003 (along with 2007 and 2010, which i tested it with).

  3. dianep on June 2, 2011 at 6:14 am

    Another comment from the old blog, author unknown:

    “Very nice piece of code. However, I had my own fonts specified and by running this, they kept changing to the default “Times New Roman”. A small change to the code fixed that for me.

    Just flip the order of the following code:

    oResponse.BodyFormat = olFormat
    oResponse.Display

    to

    oResponse.Display
    oResponse.BodyFormat = olFormat

    and my own specified font formats stays. It takes less than a fraction of a second to change the format. So displaying it first does not cause any problem. “

  4. Nasar on July 11, 2011 at 10:48 pm

    Thanks for this.

    I have save the code exactly as it says above into this ThisOutlookSession project in Outlook 2010. But how do i run this? When i click ALT+F8 it comes up empty. Also when i open a plain text email and click reply or reply all it still opens up as Plain text instead of HTML which is what i want. Appreciate all your help

  5. Diane on July 12, 2011 at 5:15 am

    It runs automatically when you reply to a message. You also need to have macro security set to medium or sign the macro. (Medium, warn for all macros, is better for most users or while tweaking macros.) Set macro security to medium and restart outlook. A VBA dialog will comes up, ok it and then the macro should work.

  6. marie h w hut on July 25, 2011 at 6:19 am

    ik ging naar Bar le Duc water en wilde een email versturen,maar kreeg iets met replycode niet goed of zo telenet 220 met 2 namen beide telenet.Vandaar mijn zoektocht wat is reply code Zag er 2 replycode Alpha en reply invalid codes.Ik ben geeindigd met snap er niks van vr.gr.mariehut

  7. Diane Poremsky on July 27, 2011 at 6:39 am

    Something may have gotten lost in translation… but if i understand it correctly, you couldn’t send an email while using public internet? This is common – many sites block smtp port 25 and make you use a different one or authenticate with your server. If its something else, sorry :(

  8. Tony D. on July 28, 2011 at 7:29 am

    This works great on Outlook 2010 (14.0) 32 bit version except that my custom fonts on the signatures do not propagate. HTML yes, my fonts and colors no. Any ideas?

  9. Diane Poremsky on July 28, 2011 at 8:21 am

    Are you using the
    oResponse.Display
    oResponse.BodyFormat = olFormat
    change?

    I’ll have to check it, but it could be because the signature is added before the conversion.

  10. Tony D. on August 1, 2011 at 2:08 pm

    Yes I made that change in all 3 places.
    I also found both the original and changed version will not run under 64bit Outlook 2010 :/
    Thanks for you help!!

  11. Ben on September 1, 2011 at 3:13 am

    Hi

    We still cannot get the HTML Signature to come up when using this code. The code does work and i can confirm the email is now in HTML, but its still using the plan text version of the sig?

    Any way to fix this?

  12. Diane Poremsky on September 1, 2011 at 6:26 am

    Based on discussions with Outlook developers, they believe the signature is added before the code makes the conversion.

    Right click on the signature – do you see the signature menu or the standard context menu?

  13. Mark on September 25, 2011 at 1:34 pm

    I found this page in the search for making all my replies HTML so that I could always include my classy html signature with image links for self-promotion purposes.

    I simply hate the vba editor and all the silly macro stuff, I always seem to get some error message. I fiddled round for hours trying to get this script (and another modified one on some other site) to work, but at best, it would make the font Times New Roman no matter what order of those two lines there, and my html signatures still don’t work fully anyway, which was the whole point of the exercise. So it’s not really very adequate.

    But I found a cool solution, albeit a commercial one: a brilliant third-party outlook add-on, bells & whistles: http://www.emailaddressmanager.com/outlook-bells.html. 30 bucks was worth it for me. it does some other cool things which I’m using now too.

    It does the change from plain text to html in some other way which is as if you clicked the html button in the ribbon on every email. I guess it loads the macro at the loading of every new message reply. And what satisfies my needs is its signature option. voila!

    it very smartly inserts the third party html signature that you make and assign, as a second step after the change to html. so it’s PERFECT in other words!!!!!

    hope my comment helps someone out there.

  14. Andy Wright on April 13, 2012 at 2:46 am

    Thanks for this, with the altering of Macro security this now works just fine.
    I had the problem mentioned by other poster whereby the signiature is inserted in plain text not HTML.
    My way round the problem is to set outlook to not automatically add a sig to replies.
    I then click reply and then click insert signiature
    The sig has a few lines of text in my preferred font above the sig image, so I can then just click in that section and start typing in the desired font.
    Yes this is a bit of a faff, but it leaves me with $30 to spend on beer instead :)

  15. Diane Poremsky on April 17, 2012 at 4:37 am

    Beer is better than outlook. :) Depending on your version of Outlook, you can customize the toolbar, ribbon, or QAT to make the Insert signature command a step away, reducing your effort further.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


Outlook Daily Tips by Email

*  Your Email Address:

Resources

Ask questions and share your knowledge in Outlook Forums.

More Outlook and Exchange articles available at Outlook and Exchange Solutions Center

Follow me on:

Follow @Outlooktips on Twitter   Join Outlooktips on Facebook



Subscribe to our Exchange Messaging Outlook weekly newsletter

*  Email Address: