VBA:生成电子邮件发件人列表

VBA:生成电子邮件发件人列表,vba,outlook,Vba,Outlook,我是VBA新手,我正在尝试生成过去8小时内向我的outlook帐户发送电子邮件的所有人的列表,并将其放入发件人列表,但现在它甚至没有进入我的while循环。我确信.Find(“[ReceivedTime]>checkTime”)有问题,但我不知道如何检查这个问题。感谢您的帮助 Dim myNameSpace As Outlook.NameSpace Dim myInbox As Outlook.Folder Dim myFolder As Outlook.Folder Dim myItems

我是VBA新手,我正在尝试生成过去8小时内向我的outlook帐户发送电子邮件的所有人的列表,并将其放入发件人列表,但现在它甚至没有进入我的while循环。我确信
.Find(“[ReceivedTime]>checkTime”)
有问题,但我不知道如何检查这个问题。感谢您的帮助

Dim myNameSpace As Outlook.NameSpace
Dim myInbox As Outlook.Folder
Dim myFolder  As Outlook.Folder
Dim myItems As Outlook.Items
Dim myItem As Object
Dim senderList As String
Dim checkTime As String

checkTime = Format(Now - 0.3, "ddddd h:nn AMPM") 

Set myNameSpace = Application.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myFolder = myInbox.Folders("Daily Logs")
Set myItems = myFolder.Items

Set myItem = myItems.Find("[ReceivedTime] > checkTime")

While TypeName(myItem) <> "Nothing"
    senderList = senderList & myItem.SenderName
    Set myItem = myItems.FindNext
Wend
将myNameSpace设置为Outlook.NameSpace
将我的收件箱暗显为Outlook.Folder
将myFolder设置为Outlook.Folder
将myItems暗显为Outlook.Items
将myItem设置为对象
Dim senderList作为字符串
作为字符串的Dim checkTime
检查时间=格式(现在为-0.3,“DDD h:nn AMPM”)
设置myNameSpace=Application.GetNamespace(“MAPI”)
设置myInbox=myNameSpace.GetDefaultFolder(olFolderInbox)
设置myFolder=myInbox.Folders(“每日日志”)
设置myItems=myFolder.Items
设置myItem=myItems.Find(“[ReceivedTime]>checkTime”)
而TypeName(myItem)“Nothing”
senderList=senderList&myItem.SenderName
设置myItem=myItems.FindNext
温德

find子句需要比较一个时间,但正如所写的那样,它是在比较文本“checktime”

这是因为“checktime”位于引号内,这使其成为字符串的一部分,而不是位于充当变量的引号外

尝试将变量从双引号中移出,并使用&运算符将其连接起来。应使用单引号限定日期字符串(这是Find函数所期望的):

如果运行此代码并查看即时窗口,您将能够很容易地看到差异:

Debug.Print "[ReceivedTime] > checkTime"
Debug.Print "[ReceivedTime] > '" & checkTime & "'"
参考


find子句需要比较一个时间,但正如所写的,它是比较文本“checktime”

这是因为“checktime”位于引号内,这使其成为字符串的一部分,而不是位于充当变量的引号外

尝试将变量从双引号中移出,并使用&运算符将其连接起来。应使用单引号限定日期字符串(这是Find函数所期望的):

如果运行此代码并查看即时窗口,您将能够很容易地看到差异:

Debug.Print "[ReceivedTime] > checkTime"
Debug.Print "[ReceivedTime] > '" & checkTime & "'"
参考