I am trying to run the macro below in Excel.
I get
error 438 object doesn't support this property or method
on the line If OutlookMail.ReceivedTime >= Range("From_date").Value Then
Option Explicit
Sub getDataFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim objOwner As Outlook.Recipient
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set objOwner = OutlookNamespace.CreateRecipient("[email protected]")
objOwner.Resolve
If objOwner.Resolved Then
Set Folder = OutlookNamespace.GetSharedDefaultFolder(objOwner, olFolderInbox)
End If
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= Range("From_date").Value Then
Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_categories").Offset(i, 0).Value = OutlookMail.Categories
Range("eMail_flag_status").Offset(i, 0) = OutlookMail.FlagStatus
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
ActiveSheet
might not have that range which is what it's attempting to do with your current code – Zac