Get Outlook's Internet Headers using VBA

Last reviewed on March 9, 2015   —  4 comments

Use this code sample and function to display the Internet header of selected message in a new message form.

Read Internet Header

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
        End With
    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'
    ' Outlook: 2007'
    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:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

More Information

Retreiving Internet Headers Using VBA in Outlook 2007/2010 Includes a code sample to use with Run a Script rule.

About Diane Poremsky

Diane Poremsky
A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Please post long or more complicated questions at Outlook forums by

4 responses to “Get Outlook's Internet Headers using VBA”

  1. kixtart

    I'm 100% ignorant of how to even start this process. Do I begin by opening Notepad, and pasting the above code into a new txt file? Then what? I'm a sysadmin and have only done batch file scripting up to this point, somehow. Please don't blast me for that. :-)

    1. Diane Poremsky

      See - that should get you pointed in the right direction.

  2. Jane Smith

    how do i use the information this is giving me? olMsg.body was not working

Leave a Reply

If the Post Comment button disappears, press your Tab key.

This site uses XenWord.