PDA

View Full Version : [SOLVED:] Retrieving outlook mail items



freshpoet
08-13-2018, 08:12 AM
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

gmayor
08-13-2018, 08:25 PM
Assuming that the start_of_month and end_of_month contain dates then


For Each OutlookMail In Folder.Items
If TypeName(OutlookMail) = "MailItem" Then
If CDate(OutlookMail.ReceivedTime) >= Range("Start_of_Month").value Then
If CDate(OutlookMail.ReceivedTime) <= Range("End_of_Month").value Then
should work.

freshpoet
08-14-2018, 07:14 AM
Hi gmayor,

thank you so much it works!

I never would have figured out that the received time had to be converted into data type date.