How Can We Help?

Categories

Outlook – Determine the Full Folder Path of a mail – VBAscript

You are here:
< Back

Where is the message stored you’re looking at? This macro tells you and can even open the folder for you.

If you search in multiple folders for an e-mail, Outlook can tell you the name of the folder the e-mail has been found in. But if you have multiple folders with the same name, this information is quite useless. This macro tells you the full folder path. Additionally, it offers to switch to the folder.

If you used the advanced search, it’s necessary to open the e-mail first before calling the macro.

Public Sub GetItemsFolderPath()
Dim obj As Object
Dim F As Outlook.MAPIFolder
Dim Msg$
Set obj = Application.ActiveWindow
If TypeOf obj Is Outlook.Inspector Then
Set obj = obj.CurrentItem
Else
Set obj = obj.Selection(1)
End If
Set F = obj.Parent
Msg = “The path is: ” & F.FolderPath & vbCrLf
Msg = Msg & “Switch to the folder?”
If MsgBox(Msg, vbYesNo) = vbYes Then
Set Application.ActiveExplorer.CurrentFolder = F
End If
End Sub

 

See how to open the VBA environment of Microsoft Outlook, and how to add macros to ThisOutlookSession.

The VBA editor is the development environment for your own macros. To open it press ALT+F11. Then press CTRL+R to open the project explorer, which lists all available code modules.

Where do I insert Macros?
At the beginning there’s only the modul ThisOutlookSession, which you can see under Project1/Microsoft Outlook Objects in the project explorer. Open the module by a double click on it. You can paste all macros in to this module.

 

Assign a macro to a button

Add a macro button to the Quick Access Toolbar

Click File > Options > Quick Access Toolbar.

In the Choose commands from list, click Macros.

Select the macro you want to assign a button to.

Click Add to move the macro to the list of buttons on the Quick Access Toolbar.

To replace the default macro icon with a different button for your macro, click Modify.

Under Symbol, select a button icon for your macro.

To use a friendlier name for the button, in the Display name box, enter the name you want.

You can enter a space in the button name.

Click OK twice.