Outlook has the ability to open an email in your browser. This is especially handy with Outlook 2007 and 2010 which does not support the full HTML/CSS specification. Opening a message in the browser allows you to see the message as it would appear if Outlook did support the full HTML/CSS specification. Unfortunately, Outlook always opens the message in Internet Explorer, completely ignoring the default browser setting. It’s a minor annoyance, unless of course you really don’t like IE. There aren’t any settings, or at least none I know of, for altering this behavior. While there isn’t a solution, there is a work-around.
Scripting to the rescue. With a few lines of code we can create a routine that opens a message in the default browser. We can also add the ability to open a message in the browser without having to open it in Outlook first. The solution is appallingly simple. All the code does is determine if a message is already open, or if it should act on the selected message. Once it knows that, it saves the message to your system’s Temp folder, then issues a command to open it in the default browser. This only works for messages, so if you don’t have a message open or selected, then the code displays an error message.
A word of caution about opening messages in the browser. Outlook’s built-in safeguards provide some protection from potentially malicious content in messages. In fact, Microsoft goes so far as to warn you by displaying this dialog-box when you use the built-in View in Browser action. This solution doesn’t provide a warning, although you could add one if you wanted, so please be careful about what you open in the browser.
This solution should work in any version of Outlook.
Adding the Code to Outlook.
- Start Outlook
- Press ALT+F11 to open the Visual Basic Editor
- If not already expanded, expand Microsoft Office Outlook Objects
- If not already expanded, expand Modules
- Select an existing module (e.g. Module1) by double-clicking on it or create a new module by right-clicking Modules and selecting Insert > Module.
- Copy the code from the code snippet box and paste it into the right-hand pane of Outlook’s VB Editor window
- Edit the code as needed. I placed a comment where changes can occur.
- Click the diskette icon on the toolbar to save the changes
- Close the VB Editor
'The declaration MUST appear at the top of the module before any other code Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) _ As Long Private Sub OpenInDefaultBrowser() Const MACRO_NAME = "Open Message in Default Browser" Dim lngRet As Long, strURL As String, olkMsg As Outlook.MailItem On Error Resume Next Select Case TypeName(Application.ActiveWindow) Case "Explorer" Set olkMsg = Application.ActiveExplorer.Selection(1) Case "Inspector" Set olkMsg = Application.ActiveInspector.CurrentItem End Select If TypeName(olkMsg) <> "Nothing" Then If olkMsg.Class = olMail Then strURL = Environ("TEMP") & "\" & RemoveIllegalCharacters(olkMsg.Subject) & ".htm" olkMsg.SaveAs strURL, olHTML lngRet = ShellExecute(0, "open", strURL, 0, 0, 1) Else msgbox "You can only open an email in the browser.", vbCritical + vbOKOnly, MACRO_NAME End If Else msgbox "You do not have an item open or selected.", vbCritical + vbOKOnly, MACRO_NAME End If On Error GoTo 0 Set olkMsg = Nothing End Sub Function RemoveIllegalCharacters(strValue As String) As String ' Purpose: Remove characters that cannot be in a filename from a string.' ' Written: 4/24/2009' ' Author: BlueDevilFan' ' Outlook: All versions' RemoveIllegalCharacters = strValue RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "<", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, ">", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, ":", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, Chr(34), "'") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "/", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "\", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "|", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "?", "") RemoveIllegalCharacters = Replace(RemoveIllegalCharacters, "*", "") End Function
Using the Code.
- Select or open a message
- Run the OpenInDefaultBrowser macro to open the item in the default browser
Running with a single click.
You can add toolbar buttons (Outlook 2003) or QAT buttons (Outlook 2007/2010) to run the macro with a single click. Here’s a link to a page that explains how to do both.