Hi all,
I have the below code to extract emails from a particular contact in outlook (inbox) and from a particular date to now. The highlighted line of code is the problem. Here is the code I have so far:
Thanks in advance
I have the below code to extract emails from a particular contact in outlook (inbox) and from a particular date to now. The highlighted line of code is the problem. Here is the code I have so far:
Rich (BB code):
Sub GetFromOutlook()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox)
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= Range("FromDate").Value And ContactItem.LastName = "Williams" Then
Range("eMail_subject").Offset(i, 0).Value = OutlookMail.Subject
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_sender").Offset(i, 0).Value = OutlookMail.SenderName
Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body
i = i + 1
End If
Next OutlookMail
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
<strike></strike>
Thanks in advance