I'm trying to import data from my Outlook inbox given a specified date and time.
My problem is the macro pulls data from the first email it sees multiple times.
It does just fine with subsequent emails. How do I pull data from each email only once?
The code is basically a template I found online.
I tried getting the loop to check for duplicates and clear the contents if a duplicate was found but I got type mismatch errors.
Dim OUTAPPLICATION As Outlook.Application
Dim OUTNAMESPACE As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Dim Time As Date
Set OUTAPPLICATION = New Outlook.Application
Set OUTNAMESPACE = OUTAPPLICATION.GetNamespace("MAPI")
Set Folder = OUTNAMESPACE.GetDefaultFolder(olFolderInbox)
i = 1
For Each OutlookMail In Folder.Items
If OutlookMail.ReceivedTime >= range("Date").Value Then
range("Footprints").Offset(i, 0).Value = OutlookMail.Subject
range("Type").Offset(i, 0).Value = OutlookMail.SenderName
range("ETA").Offset(i, 0).Value = OutlookMail.ReceivedTime
range("SH").Offset(i, 0).Value = OutlookMail.Body
range("Status").Offset(i, 0).Value = OutlookMail.CC
i = i + 1
End If
Next OutlookMail
There are no errors. The program takes a long time to run. Is there a way to get it to run faster?
Add this code before ending the code
Set Folder = Nothing
Set OUTNAMESPACE = Nothing
Set OUTAPPLICATION= Nothing
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.