Hello All,
Is there any way to get the list of email addresses from outlook inbox which I received in last one year?
Hello All,
Is there any way to get the list of email addresses from outlook inbox which I received in last one year?
Please make the Post as solved, when you get your answer & Click * if you like my suggestion
Try this macro;
Put your start date and end date of the emails you want to retrieve in A1 and B1. Email sender address in column C and date received in column D
Note the comment on the second line (Tools>References in your VBA window)
![]()
Option Explicit Public Sub ReadOutlookEmails() 'Microsoft Outlook XX.X Object Library is required to run this code Dim objFolder As Outlook.Folder Dim objNS As Outlook.Namespace Dim objMail As Outlook.MailItem Dim lCounter As Long Dim Count As Long Range("C:D") = "" Set objNS = Outlook.GetNamespace("MAPI") Set objFolder = objNS.GetDefaultFolder(olFolderInbox) On Error Resume Next For lCounter = 1 To objFolder.Items.Count Application.DisplayStatusBar = True Application.StatusBar = "Reading mail item number " & lCounter Set objMail = objFolder.Items.Item(lCounter) If objMail.ReceivedTime > Range("B1").Value + 1 Then Exit For End If If objMail.ReceivedTime >= Range("A1").Value Then Count = Count + 1 Sheet1.Range("C" & Count).Value = objMail.SenderEmailAddress Sheet1.Range("D" & Count).Value = objMail.ReceivedTime End If Next On Error GoTo 0 MsgBox "Done", vbInformation Application.DisplayStatusBar = False End Sub
Last edited by Croweater; 02-06-2023 at 03:16 AM.
I am not getting the email address.Just the dates. Is there something i need to modify?
Can you make this one line addition to the code and tell me what it says in column E?
![]()
Count = Count + 1 Sheet1.Range("E" & Count).Value = objMail.SenderEmailType Sheet1.Range("C" & Count).Value = objMail.SenderEmailAddress Sheet1.Range("D" & Count).Value = objMail.ReceivedTime
Last edited by Croweater; 02-06-2023 at 05:12 AM.
excelforum.xlsm
here is the sample file
See edited post #4
SMTP & ET in column E
I cannot test properly as I don't get emails from an Internal Exchange, but try this modification;
![]()
Option Explicit Public Sub ReadOutlookEmails() 'Microsoft Outlook XX.X Object Library is required to run this code Dim objFolder As Outlook.Folder Dim objNS As Outlook.Namespace Dim objMail As Outlook.MailItem Dim lCounter As Long Dim Count As Long Sheet1.Range("C:D") = "" Set objNS = Outlook.GetNamespace("MAPI") Set objFolder = objNS.GetDefaultFolder(olFolderInbox) On Error Resume Next For lCounter = 1 To objFolder.Items.Count Application.DisplayStatusBar = True Application.StatusBar = "Reading mail item number " & lCounter Set objMail = objFolder.Items.Item(lCounter) If objMail.ReceivedTime > Sheet1.Range("B1").Value + 1 Then Exit For End If If objMail.ReceivedTime >= Range("A1").Value Then Count = Count + 1 If objMail.SenderEmailType = "SMTP" Then Sheet1.Range("C" & Count).Value = objMail.SenderEmailAddress Else Sheet1.Range("C" & Count).Value = objMail.Sender.GetExchangeUser.PrimarySmtpAddress End If Sheet1.Range("D" & Count).Value = objMail.ReceivedTime End If Next On Error GoTo 0 MsgBox "Done", vbInformation Application.DisplayStatusBar = False End Sub
Last edited by Croweater; 02-06-2023 at 05:43 AM.
Still not.
its ok, I will try to explore with the code you gave. Thanks
No problem. You may have to step through the code and see what is happening in there.
I'm surprised it is not working for the internet emails though...it picked all of mine out.
Let me know how it goes. I'll try to help more if I can.
I got this from another server and is fetching the id.
https://www.mrexcel.com/board/thread...ok-vba.444863/
OK...glad you got it sorted out.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks