Last November I added a post with a VBA code fragment that retrieves the internet headers for a message. Here’s a practical example of how that code can be used to solve a problem.
Today I ran across a tweet from S1monJones commenting on how difficult it is to see the internet headers of a message in Outlook 2010. Simon makes a good point. It would be nice to be able to get to the headers without having to drill down through several selections. Fortunately there is a simpler way. By taking the code from my original post and adding a routine that calls it and passes the currently open/selected message, Simon can get to the headers with a single click.
- Start Outlook
- Press ALT+F11 to open Outlook’s VB editor
- If not already expanded, expand Project1
- If not already expanded, expand Modules and select Module1. If Module1 doesn’t exist, right-click Modules and select Insert > Module.
- Copy the code below and paste it into the right-hand pane of Outlook’s VB Editor window
- Click the diskette icon on the toolbar to save the changes
- Click the File tab.
- Click Options > Quick Access Toolbar.
- In the list under Choose commands from:, choose Macros. Find and select Project1.Module1.RapidViewingInternetHeaders
- Click the Add button to add the macro, and then click the Modify… button to select a button image to associate with the macro.
- Click OK. You should see your new button on the Quick Access Toolbar above the File tab.
Sub RapidViewingInternetHeaders() Dim olkItm As Object, objIE As Object Select Case TypeName(Application.ActiveWindow) Case "Explorer" Set olkItm = Application.ActiveExplorer.Selection(1) Case "Inspector" Set olkItm = Application.ActiveInspector.CurrentItem End Select If olkItm.Class = olMail Then Set objIE = CreateObject("InternetExplorer.Application") With objIE .Navigate2 "about:blank" Do Until .readyState = 4 DoEvents Loop .Document.Body.innerText = GetInetHeaders(olkItm) .Visible = True End With End If Set olkItm = Nothing Set objIE = Nothing End Sub Function GetInetHeaders(olkMsg As Outlook.MailItem) As String ' Purpose: Returns the internet headers of a message.' ' Written: 4/28/2009' ' Author: BlueDevilFan' ' Outlook: 2007' Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E" Dim olkPA As Outlook.PropertyAccessor Set olkPA = olkMsg.PropertyAccessor GetInetHeaders = olkPA.GetProperty(PR_TRANSPORT_MESSAGE_HEADERS) Set olkPA = Nothing End Function
To view the headers Simon will select or open a message and then click the button on the Quick Access Toolbar. The code will fetch the header from the message and display it in an Internet Explorer window.