Skip to content

Instantly share code, notes, and snippets.

@adamsmith
Created August 25, 2012 01:51
Show Gist options
  • Save adamsmith/3458680 to your computer and use it in GitHub Desktop.
Save adamsmith/3458680 to your computer and use it in GitHub Desktop.
Change reply format in Outlook to HTML and insert signature
' I like to read messages in Plain Text, but I want to reply in HTML, and I have HTML markup in my
' email signature. Outlook doesn't let you read in Plain Text and reply in HTML by default.
' My VBA code to do this is below. It watches for new Compose windows, and when appropriate
' switches the format to HTML, and inserts my signature, followed by down, down, delete delete up
' up up up (sounds like a video game code, I know; it removes two annoying line breaks after the
' sig and moves the cursor to the top)...
Option Explicit
Private WithEvents oInspectors As Inspectors
Private WithEvents oNewInspectorToWatch As Inspector
Private Sub Application_Startup()
Set oInspectors = Application.Inspectors
End Sub
Private Sub oInspectors_NewInspector(ByVal ins As Inspector)
If ins.CurrentItem.BodyFormat <> olFormatHTML And Not ins.CurrentItem.Sent Then
Set oNewInspectorToWatch = ins
End If
End Sub
Private Sub oNewInspectorToWatch_Activate()
' Note: this assumes the name of the signature to use is "personal"
' Adjust the text "personal" below accordingly
oNewInspectorToWatch.CommandBars.Item("Menu Bar").Controls.Item("F&ormat").Controls.Item("&HTML").Execute
oNewInspectorToWatch.CommandBars.Item("Menu Bar").Controls.Item("&Insert").Controls.Item("&Signature").Controls.Item("personal").Execute
Dim curInspector As Inspector
Set curInspector = oNewInspectorToWatch
Set oNewInspectorToWatch = Nothing
DoEvents
curInspector.Activate ' Make sure focus wasn't stolen during the last DoEvents
' Remove extra line breaks after sig, and restore cursor to top
' (My signature is two lines long, so others might have to change the sequence here)
If Left(curInspector.CurrentItem.Subject, 3) = "FW:" Then
' Cursor starts out in the To: window
SendKeys "{TAB}{TAB}{TAB}{TAB}{DOWN}{DOWN}{DEL}{DEL}{UP}{UP}{UP}{UP}+{TAB}+{TAB}+{TAB}+{TAB}"
Else
' Cursor starts out in the editor window
SendKeys "{DOWN}{DOWN}{DEL}{DEL}{UP}{UP}{UP}{UP}"
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment