[英]Importing email data from Outlook
I'm trying to import data from my Outlook inbox given a specified date and time.我正在尝试从指定日期和时间的 Outlook 收件箱中导入数据。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.