PM's that relate to a thread should be contained in that thread. I don't know how to help more other than post 8. It is up to you to try the Debug.Print troubleshooting as I said. Paste the results of the Immediate window after a run if it makes no sense.
Dim n As Long
Sub Get_data()
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder
Dim Date1, Date2
Date1 = "01/20/2017"
Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder
n = 2
Call Get_Emails(olFolder, Date1)
Set olNS = Nothing
Set olFolder = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub
Sub Get_Emails(olfdStart As Outlook.MAPIFolder, Date1)
Dim olFolder As Outlook.MAPIFolder
Dim olObject As Object
Dim olMail As Outlook.MailItem
Dim Recivedt As Date
For Each olObject In olfdStart.Items
If TypeName(olObject) = "MailItem" Then
If olObject.ReceivedTime <= Date1 Then
n = n + 1
Set olMail = olObject
'Sno
Cells(n, 1) = n
'Universal id
Cells(n, 2) = olMail.ConversationID
'Email id
Debug.Print GetSmtpAddress(olObject), "GetSmtpAddress"
Debug.Print Cells(n, 3).Value, "Cells(n, 3).value"
Debug.Print olMail.SenderEmailAddress, "olMail.SenderEmailAddress"
Cells(n, 3) = olMail.SenderEmailAddress
'Date and time workings
Cells(n, 4) = olMail.ReceivedTime
'Size
Cells(n, 6) = olMail.Size
'Subject
Cells(n, 7) = olMail.Subject
End If
End If
Next
Set olMail = Nothing
Set olFolder = Nothing
Set olObject = Nothing
End Sub
'http://forums.codeguru.com/showthread.php?441008-Extract-sender-s-email-address-from-an-Exchange-email
Private Function GetSmtpAddress(ByVal item As Outlook.MailItem) As String
Dim sAddress As String
Dim recip As Outlook.Recipient
Dim exUser As Outlook.ExchangeUser
Dim oOutlook As Outlook.Application
Dim oNS As Outlook.Namespace
Set oOutlook = New Outlook.Application
Set oNS = oOutlook.GetNamespace("MAPI")
If UCase$(item.SenderEmailType) = "EX" Then
Set recip = oNS.CreateRecipient(item.SenderEmailAddress)
Set exUser = recip.AddressEntry.GetExchangeUser()
sAddress = exUser.PrimarySmtpAddress
Else
sAddress = item.SenderEmailAddress
End If
GetSmtpAddress = sAddress
Set oNS = Nothing
Set oOutlook = Nothing
End Function