我正在尝试创建一个宏,它可以使用我想要的类别和收到电子邮件的日期有效地搜索 Outlook 中的共享邮箱。
txtCat 将是类别
txtDate 是我将以这种格式输入日期的地方:“mm/dd/yyyy”
私有子 CommandButton1_Click()
Dim outlookapp
Dim olns As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Object
Dim myTasks
Dim myrecipient As Outlook.Recipient
Dim dateString As Long
Dim strfilter As String
Set outlookapp = CreateObject("Outlook.Application")
Set olns = outlookapp.GetNamespace("MAPI")
Set myrecipient = olns.CreateRecipient("Cmaintenancesupport2")
myrecipient.Resolve
Dim strCat As String
'txtCat is the category
'txtDate is the date
Set Fldr = olns.GetSharedDefaultFolder(myrecipient, olFolderInbox)
strCat = UserForm1.txtCat.Text
strfilter = "[Categories] = """ & strCat & """"
dateString = CDate(UserForm1.txtDate.Text)
Set myTasks = Fldr.Items.Restrict(strfilter) 'filters the desired category in the SharedDefault Mailbox
Set myTasks = myTasks.Restrict("[ReceivedTime] = '" & Format(dateString, "DDDDD HH:NN") & "'") 'adds another filter by date
For Each olMail In myTasks
olMail.Display
Next
End Sub
我将 mytasks 设置了两次,因为我只是从以前有效的项目中重组此代码(分类电子邮件 > 按天过滤 > 搜索主题行),但不知何故它没有向我显示任何结果。
这里应该发生在类别过滤器之后,它应该所有已经分类的具有所需日期的电子邮件。