Good morning/afternoon/evening,
I'm trying to pull in some email data and have the below error on the Debug line.
I have the Outlook 16.0 Reference Library added.
Any suggestions?
Many thanks.
I'm trying to pull in some email data and have the below error on the Debug line.
I have the Outlook 16.0 Reference Library added.
Any suggestions?
Many thanks.
VBA Code:
Sub GetFromOutlook()
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myitem As Object
Dim i As Integer
Dim myDate As Date
Dim sht As Worksheet
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myitems = myInbox.Items
Set sht = Sheets("Data")
myDate = Date
i = 1
For Each myitem In myitems
Debug.Print myitem.ReceivedTime
If myitem.ReceivedTime >= myDate And InStr(1, myitem.Subject, "Town") > 0 Then
sht.Cells(i + 1, 1) = myitem.Subject
sht.Cells(i + 1, 2) = myitem.ReceivedTime
sht.Cells(i + 1, 3) = myitem.SenderName
sht.Cells(i + 1, 4) = myitem.Body
i = i + 1
End If
Next myitem
End Sub