• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Extract Email Address from Outlook messages|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Extract Email Address from Outlook messages|VBA & Macros|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosExtract Email Address from Outlook …
sp_PrintTopic sp_TopicIcon
Extract Email Address from Outlook messages
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
1
June 2, 2020 - 9:00 am
sp_Permalink sp_Print

Hi,

Could you please help me.

I have a lot of outlook messages in folder in my PC and I want to extract these "Subject, Received Date/Time, To, CC, Message Path"

Example:

Subject: Test

Received Date/Time: Sun 5/31/2020 9:24 AM

To: bill@xcompany.com

CC: Mike@intel.com

Message Path: E:\messages\Case (# 44347_2) Inquiry.msg

I found attached macro in myonlinetraininghub.com and I need your help to update it.

 

Thanks;

Marsil

sp_AnswersTopicSeeAnswer See Answer
Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 414
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
2
June 2, 2020 - 3:08 pm
sp_Permalink sp_Print

Hello

Are the emails saved as seperate .msg in a  folder on your harddrive or are they still in outlook?

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
3
June 2, 2020 - 8:15 pm
sp_Permalink sp_Print

Hi Purfleet,

 

Thank you for fast response.

Yes I have all messages in Outlook.

Note: I have two account in my outlook and I want to get data for specific folder, Please check attached image.

Grateful for your support..

Thanks;

Marsil

Outlook-1.pngImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage Outlook-1.png (13 KB)
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
4
June 4, 2020 - 2:35 pm
sp_Permalink sp_Print

Hi Marsil.

See attached file. From your image it looks like you want emails that are not in your default email account.  In which case you need to change this line in the VBA

Set Folder = OutlookNS.Folders("NAME OF EMAIL ACCOUNT").Folders("Inbox")

Insert the NAME of your account, NOT the email address.  So if your account is in the name Marsil Sarvis then insert that.

I don't understand what you are referring to when you talk about the Message Path.  Each email will be stored within the mailbox not separately on the hard drive as .msg files - which is what Purfleet was asking about too.

Regards

Phil

The following users say thank you to Philip Treacy for this useful post:

Purfleet
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
5
June 4, 2020 - 7:53 pm
sp_Permalink sp_Print sp_EditHistory

Hi Phil,

I want to thank you for your continued support.

I saved it path as my target is  save all these messages in Path and send to another person to read email body and signatures then extract valuable information.

Could you please help me as I face attached issues when I try to run the macro please.

Grateful for your support..

1.pngImage Enlarger

2.pngImage Enlarger

 

 

Thanks;

Marsil

sp_PlupAttachments Attachments
  • sp_PlupImage 1.png (183 KB)
  • sp_PlupImage 2.png (121 KB)
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
6
June 4, 2020 - 8:27 pm
sp_Permalink sp_Print sp_EditHistory

Hi Marsil,

You need to set a reference to the Microsoft Outlook 16.0 Object Library in the VBA editor.  Sorry I thought you'd already done this as your first post gave me the impression you'd run the code already.

Open the Excel file, go into the VBA editor and then from the menu click Tools -> References and check the box beside the library

Regards

Phil

 

vba tools referencesImage Enlarger

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
7
June 4, 2020 - 8:36 pm
sp_Permalink sp_Print

Hi Phil,

 

Please see attached image and I think there is something is wrong 3.pngImage Enlarger

from my side.

 

Thanks

Marsil

sp_PlupAttachments Attachments
  • sp_PlupImage 3.png (29 KB)
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
8
June 5, 2020 - 11:01 am
sp_Permalink sp_Print

Hi Phil,

I can't see "Outlook 16.0 Object Library" in References window, please check attached image.

It is contain " missing microsoft outlook 16.0 object library"

Please can you let me know how I can add "Outlook 16.0 Object Library" in References window?

3-1.pngImage Enlarger

 

Thanks;

Marsil

sp_PlupAttachments Attachments
  • sp_PlupImage 3-1.png (29 KB)
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
9
June 5, 2020 - 11:33 am
sp_Permalink sp_Print

Hi Guys,

Try the attached file.  I've rewritten it to use late binding so you don't need to set a reference to the Outlook library.

Cheers

Phil

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
10
June 5, 2020 - 11:47 pm
sp_Permalink sp_Print

Hi Phil

It works perfectly That's a huge help - thanks!

I check macro result and I have below notes, Please take a look.

----Macro give error when it face “meeting invitation email”, please check attached image.

    If u can help me to ignore any “meeting invitation email” to let the macro complete to extract all messages.

 

-----In To & CC columns contain the display name not emails address.

      If you can update this to extract the email address not display name.

       Ex: the current result is “Marsil Sarvis” , please I need marsil-sarvis@xxxx.com

Thanks again. Couldn't have done it without you.

Thanks;

Marsil

 

meeting-invitation-email.pngImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage meeting-invitation-email.png (15 KB)
Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
11
June 8, 2020 - 1:43 pm
sp_Permalink sp_Print

Hi Marsil,

Try this.

regards

Phil

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
12
June 8, 2020 - 5:37 pm
sp_Permalink sp_Print

Hi Phil,

Please check attached macro result.

Thanks,

Marsil

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
13
June 8, 2020 - 8:55 pm
sp_Permalink sp_Print

Hi Marsil,

That is a Microsoft Exchange user.  Are you connected to Exchange?

Phil

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
14
June 8, 2020 - 8:58 pm
sp_Permalink sp_Print sp_EditHistory

Hi Phil,

I think yes, I run the macro from my PC and I don't open the outlook online.

Please let me know what's the issue.

 

Thanks;

Marsil

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
15
June 11, 2020 - 11:42 am
sp_Permalink sp_Print

Hi Marsil,

Please see the attached file which is based on some code from https://stackoverflow.com/ques.....om-outlook

I can't really test this for you as I am not connected to your Exchange server and the code relies on this.

Regards

Phil

sp_AnswersTopicAnswer
Answers Post
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
16
June 11, 2020 - 7:29 pm
sp_Permalink sp_Print

Hi Phil,

Thank you for your always support.

I checked the macro and it is ok, as I found the email address.

It just need to fix below point.

Please check attached, you will find in Column A, the Send Display name "Marsil Sarvis"  and In Column D, you will find the email address for sender as below

Marsil Sarvis <marsil-sarvis@xxxx.com>  and there is no data in E column.

So please can you handle this as below.

Column A, contain the email address for sender.

Column D, contain the email address for TO

Column E, contain the email address for CC.

Thanks is not enough, but really don't know what else say to you.

Thanks,

Marsil

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
17
June 12, 2020 - 3:21 pm
sp_Permalink sp_Print

No worries Marsil.

To get the email address for the sender change

Range("A1").Offset(i, 0).Value = Email.SenderName

to

Range("A1").Offset(i, 0).Value = Email.SenderEmailAddress

Col D should already contain the TO email address and Col E should be listing any CC email addresses.  When I test this at my end this is exactly what it is doing.

If it is not doing the same for you can you please provide a screenshot of the email showing the email(s) where it is not working.  Just the email addresses, you don't need to show the email content.

Regards

Phil

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
18
June 13, 2020 - 12:14 am
sp_Permalink sp_Print

It works perfectly, thanks Phil!

You are amazing! Thank you so much!

Thanks;

Marsil

Avatar
Philip Treacy
Admin
Level 10
Forum Posts: 1530
Member Since:
October 5, 2010
sp_UserOfflineSmall Offline
19
June 13, 2020 - 9:11 am
sp_Permalink sp_Print

You're welcome 🙂

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Louis Muti
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 218
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Blair Gallagher
Brandi Taylor
Hafiz Ihsan Qadir
Gontran Bage
adolfo casanova
Annestine Johnpulle
Priscila Campbell
Jeff Mikles
Aaron Butler
Maurice Petterlin
Forum Stats:
Groups: 3
Forums: 24
Topics: 6369
Posts: 27852

 

Member Stats:
Guest Posters: 49
Members: 32359
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.