Use this code sample and function to display the Internet header of selected message in a new message form.
Tested in Outlook 2013, also works in Outlook 2010 and 2007. For Outlook 2003 and older, see Get Internet header VBA code sample for Outlook 2003.
Sub ViewInternetHeader() Dim olItem As Outlook.MailItem, olMsg As Outlook.MailItem Dim strheader As String For Each olItem In Application.ActiveExplorer.Selection strheader = GetInetHeaders(olItem) Set olMsg = Application.CreateItem(olMailItem) With olMsg .BodyFormat = olFormatPlain .Body = strheader .Display End With Next Set olMsg = 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' ' http://techniclee.wordpress.com/ ' 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
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
Retreiving Internet Headers Using VBA in Outlook 2007/2010 Includes a code sample to use with Run a Script rule.