Hi,
I made a macro used in Excel to retrieve the email date and email sender of a shared outlook mailbox.
The program is able to retrieve all the emails within a specific month however I am getting a run time error 438 (Object doesnt support this property or method) at the end of the code even though I see it has retrieved all the email.
The error is situated at If OutlookMail.ReceivedTime >= Range("Start_of_Month").Value Then
Here is my code. Why am I getting a run time error?
Thank you!
Sub getDataFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Dim strMailboxName As String
strMailboxName = "client support"
strMailboxName1 = "Inbox"
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.Folders(strMailboxName)
Set Folder = Folder.Folders(strMailboxName1)
Set Folder = Folder.Folders("CHRISTINA")
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= Range("Start_of_Month").Value Then
If OutlookMail.ReceivedTime <= Range("End_of_Month").Value Then
Range("Email_Sender").Offset(i, 0) = OutlookMail.SenderName
Range("Email_Sender").Offset(i, 0).Columns.AutoFit
Range("Email_Sender").Offset(i, 0).VerticalAlignment = xlTop
Range("Email_Date").Offset(i, 0) = OutlookMail.SentOn
Range("Email_Date").Offset(i, 0).Columns.AutoFit
Range("Email_Date").Offset(i, 0).VerticalAlignment = xlTop
i = i + 1
End If
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub