Public Sub ReadOutlookEmails()
'Microsoft Outlook XX.X Object Library is required to run this code
'Variable declaration
Dim objFolder As Outlook.Folder
Dim objNS As Outlook.Namespace
Dim objMail As Outlook.MailItem
Dim lCounter As Long
'Set objects
Set objNS = Outlook.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
'Validation if no folder picked by the user
If TypeName(objFolder) = "Nothing" Then
Exit Sub
End If
'Read emails from Outlook folder and update details in Sheet1
For lCounter = 1 To objFolder.Items.Count
Set objMail = objFolder.Items.Item(lCounter)
Sheet1.Range("A" & lCounter + 5).Value = objMail.SenderName 'Sender name
Sheet1.Range("B" & lCounter + 5).Value = objMail.To 'To
Sheet1.Range("C" & lCounter + 5).Value = objMail.CC 'Cc
Sheet1.Range("D" & lCounter + 5).Value = objMail.Subject 'Subject
Sheet1.Range("E" & lCounter + 5).Value = objMail.ReceivedTime 'Email Received Time
Sheet1.Range("F" & lCounter + 5).Value = objMail.Attachments.Count 'Attachment Count
Next
'Show confirmation message to user
MsgBox "Done", vbInformation
End Sub
It is worth to mention that you must have MS Outlook installed in your system to use this code and you also need to add Office reference (Microsoft Outlook XX.X Object Library) in Excel VBA from Menu Bar (Tools>References…). Below are the steps to add Office 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
To use this code in your Excel file, follow below steps:
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 ‘Read Outlook Emails’
7. Right click on the shape and select ‘Assign Macro…’
8. Select ‘ReadOutlookEmails’ from the list and click on ‘Ok’ button
9. Done
VBA to Browse Outlook Folder 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…
Time & Motion Tracker is an MS Excel based tool which helps you to track Start and End time of any type of transaction or activity. The tool is developed using VBA coding which helps you to protect manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time stamp.
Custom Calendar Control for MS Access MS Access by default provides inbuilt functionality to pick dates using calendar control; however it lacks few basic functionalities which makes selecting a date bit difficult. For example, if…
Here is one more wonderful free tool from ExcelSirJi.com which makes your life easy. Time & Motion Tracker helps you to track Start and End time of any type of transaction or activity. The good thing is, it is VBA based tool which helps you to protect from manual manipulation in the data by the user. It is also easy to use, just click on Start (shortcut: Ctrl+Shift+A) or Stop (Ctrl+Shft+S) buttons to record the time
Have you ever got into situation in office where you need to count the cells in Excel sheet with specific color? If yes then you can use following code which counts the number of cells…
Here we are coming with one more exciting post which can help you to solve very basic but very important problems while writing VBA codes.
Excellent!!! a few minor modifications, and it worked perfectly!
Is Outlook that come with Windows 10 applicable? or is Microsoft Outlook required for VBA? Thanks!
You should have installed and configured Outlook available where you are running the VBA Code.
Can you do this to where you use a specified folder in the code instead of choosing each time?
Yes Rebecca, it is possible to specify the folder in the code. I suggest you to have a look at Outlook Email Management Tool. Once downloaded, we can customize your tool copy for free with remember feature, means the tool will remember last browsed folder to avoid browsing the folder again and again.
Regards,
ExcelSirJi Team