Skip to navigation
How to open a html email with one click in outlook 2007
to open a html email with one click in outlook 2007 Create Macro As I already provide you with the code, creating the macro is easy. The code has been tested with Outlook 2003 on Windows XP and Outlook 2007 on Windows Vista but should work on previous versions as well. We start up the Visual Basic Editor by going to Tools-> Macro-> Visual Basic Editor. This will open a new screen. Choose Insert-> Module to create a new module dedicated to this macro. Select the newly created module in the left pane and rename it to "InBrowser" by changing the Properties value in the pane underneath. Copy and paste the code below to the module. Sub OpenInBrowser() Dim BrowserLocation As String Dim AlwaysConvert As Boolean Dim EvaluateHTML As Boolean '=============Set your variables in the section below========================== 'The default settings are optimized for viewing newsletters and receiving 'messages with HTML forms or animated gif-files embedded in the message. 'Set the location of the executable of the browser you want to use. 'Standard value: "C:\Program Files\Internet Explorer\iexplore.exe" BrowserLocation = "C:\Program Files\Internet Explorer\iexplore.exe" 'When set to True, we will let Outlook convert the message to HTML. 'The message will be opened in the configured browser just as it 'appears in Outlook. 'Standard value: False AlwaysConvert = False 'When set to True, we will look for embedded resources in the HTML message and 'determine whether Outlook should convert the message or whether we can strip 'the HTML directly. When set to False, we will always strip the HTML and ignore 'embedded resources. 'For this setting to take effect, AlwaysConvert must be set to False. 'Standard value: True EvaluateHTML = True '=======Don't modify the code below unless you know what you are doing========= 'Get the user's TempFolder to store the item in Dim FSO As Object, TmpFolder As Object Set FSO = CreateObject("scripting.filesystemobject") Set FileName = FSO.GetSpecialFolder(2) 'Get all selected items Dim MyOlNamespace As Outlook.NameSpace Set MyOlNamespace = Application.GetNamespace("MAPI") Set MyOlSelection = Application.ActiveExplorer.Selection 'Make sure at least one item is selected If MyOlSelection.Count = 0 Then Response = MsgBox("Please select an item first", vbExclamation, MyApplName) Exit Sub End If 'Make sure only one item is selected If MyOlSelection.Count > 1 Then Response = MsgBox("Please select only one item", vbExclamation, MyApplName) Exit Sub End If 'Retrieve the selected item Set MyselectedItem = MyOlSelection.Item(1) 'construct the filename strname = "www_howto-outlook_com" FileName = FileName & "\" & strname & ".htm" 'If the message is in HTML format we directly capture the HTML from the message 'to construct our htm-file. This will allow us to capture as many HTML elements 'as possible. If it is a different format, or if the HTML mail includes embedded 'resources we let Outlook convert it to HTML. Dim OutlookConvert As Boolean OutlookConvert = True If MyselectedItem.BodyFormat = olFormatHTML And AlwaysConvert = False Then Dim rawHTML As String rawHTML = MyselectedItem.HTMLBody If EvaluateHTML = False Then OutlookConvert = False Else 'Check if there are embedded resources in the message. 'If it does, we let Outlook convert the message. If InStr(UCase(rawHTML), UCase("src=""cid:")) = 0 Then OutlookConvert = False End If End If End If 'Write the temp-file If OutlookConvert = False Then 'create the htm-file in the temp folder and write the HTML code to it Set objFile = FSO.CreateTextFile(FileName, True) objFile.Write "" & rawHTML objFile.Close Set objFile = Nothing Else 'let Outlook convert the message and save the selected item 'as htm to the temp folder MyselectedItem.SaveAs FileName, olHTML End If 'open the saved item in the browser Shell BrowserLocation & " " & FileName, vbNormalFocus 'Cleanup Set FSO = Nothing Set FileName = Nothing Set MyOlNamespace = Nothing Set MyOlSelection = Nothing Set MyselectedItem = Nothing End Sub The code copied in the Visual Basic Editor. (click on image to enlarge) You can define which browser to open the message with by editing the following line; BrowserLocation = "C:\Program Files\Internet Explorer\iexplore.exe" As you can see by default I've set it to open with Internet Explorer. Now we debug the code by choosing Debug-> Compile Project1. You shouldn't be getting errors if you've done everything correctly. If you do get errors retrace your steps and also verify that any previous code you might have in ThisOutlookSession is correct. Debug until you've solved the errors (the code provided works correctly without any modifications). To be able to run the code without setting your macro security level to medium I recommend that you sign your code which is a very easy process and only takes a minute. Create a button for the macro You can run the macro through Tools-> Macrosâ€¦ -> select the OpenInBrowser macro and then press Run. However the easiest way to access and use the macro is to create a button for it. Since the macro works on the selected item we can create the button in the main Outlook window. Follow the instructions below to create a button. 1. Set the Toolbar in edit mode by going to View-> Toolbars-> Customizeâ€¦ 2. Select the tab Commands 3. In the Categories column select Macros 4. In the Commands toolbar click on Project1.OpenInBrowser and hold down the mouse button. 5. Drag the icon to a location on the Toolbar so the pointer will loose the cross and release the mouse button to drop it in that location 6. Right click the icon to change the name and to assign it a button image you like (if you want to learn more about editing Toolbar buttons click here) 7. Press Close to leave edit mode
Information Epoch 1410836090
Small is beautiful.
Copyleft ☠ 2014