Outlook is most commonly used emailing application used in the world. Many people spend their entire day on Outlook applications to read and respond to emails. To automate certain rule-based tasks in Outlook, we can take the help of VBA. Below is one of the commonly used VBA codes to browse an Outlook folder. The code returns two values:
Outlook folder path can be used to display the selected folder path to the user and EntryID can be used to contact Outlook and read emails from the folder.
You can also read my post for reading Outlook emails in Excel
Public Sub PickOutlookFolder()
'Microsoft Outlook XX.X Object Library is required to run this code
'Variable declaration
Dim objNS As Namespace
Dim objFolder As Folder
Dim strFolderPath As String
Dim strEntryID As String
'Set Outlook Object
Set objNS = Outlook.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
strFolderPath = objFolder.FolderPath
strEntryID = objFolder.EntryID
End If
'Close the objects
Set objFolder = Nothing
Set objNS = Nothing
'Show the selected folder details on Excel sheet
Sheet1.Range("B6").Value = strFolderPath
Sheet1.Range("C6").Value = strEntryID
End Sub
It is worth to mention that you need to add Outlook reference (Microsoft Outlook XX.X Object Library) in Excel VBA from Menu Bar (Tools>References…). Below are the steps to add Outlook reference in Excel VBA:
1. From the Menu Bar, click on Tools > References…
2. Select ‘Microsoft Outlook XX.X Object Library’ and click on ‘OK’ button
1. Open an Excel file
2. Press Alt+F11
3. Insert a Module (Insert>Module) from menu bar
4. Paste the code in the module
5. Now add a shape in Excel sheet
6. Give a name to the shape like ‘Browse Outlook Folder’
7. Right click on the shape and select ‘Assign Macro…’
8. Select PickOutlookFolder from the list and click on ‘Ok’ button
9. Done
Merge Excel Files From last few months, we have been receiving frequent requests from users for a VBA tool which can consolidate Excel files from a folder. So here we come with one more free…
Delta Symbol in Excel The Greek Capital Alphabet letter Delta (▲) and is commonly discussed topic in Excel. This is being used for various purposes i.e. changes in quantity, insert the symbol in excel etc….
VBA code that will sum cells by its color through excel function. This code will really help in making the analysis and presentation better.
How to Insert Symbol in Excel? I came across many queries regarding inserting special symbols in Excel. Here we are guiding how you may do this quickly in excel. Follow these steps and you may…
How to use VBA to open Workbook in Excel? There are few VBA codes which are commonly used by every developer. One of them is giving an option to user to browse a file. Below is a…
VBA to Read Excel Data Using Connection String Sometimes as a programmer you need to read heavy (more then 5 MB) Excel files. There are two ways you can read data from Excel files: Open…