This code sample saves the selected message as an HTML files and displays it in Internet Explorer.
To use: select a message and run the macro. If more than one message is saved, only the first message is saved and opened in Internet Explorer.
Sub ViewInBrowser() Dim oApp As Object Dim FSO As Object Dim FilePath As Object Dim strUrl As String Set oApp = CreateObject("InternetExplorer.Application") Set FSO = CreateObject("Scripting.FileSystemObject") ' save in temp folder Set FilePath = FSO.GetSpecialFolder(2) strUrl = FilePath & "\ViewInBrowser.htm" Set objFile = FSO.CreateTextFile(strUrl, True) 'use selected item Set objItem = Application.ActiveExplorer.Selection.Item(1) ' save selected message as HTML Dim strHTML As String strHTML = objItem.HTMLBody objFile.Write "" & strHTML objFile.Close 'open in IE oApp.navigate (strUrl) oApp.Visible = True 'wait for page to load before passing the web URL Do While oApp.Busy DoEvents Loop 'Cleanup Set objFile = Nothing Set FSO = Nothing Set objItem = Nothing Set oApp = Nothing End Sub
How to use macros
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.
After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Open the VBA Editor by pressing Alt+F11 on your keyboard.
To put the code in a module:
- Right click on Project1 and choose Insert > Module
- Copy and paste the macro into the new module.
More information as well as screenshots are at How to use the VBA Editor