【发布时间】:2020-12-16 08:09:27
【问题描述】:
我正在使用 DASL 过滤器来搜索标记为上个月已完成的邮件。
它还返回上个月最后一天标记的项目(因此我为 9 月过滤器获取了一些 8 月项目)。另外,如果有时间偏移,我不确定是否会提取所有在 9 月标记的项目(来自 9 月最后一天的项目)。
我猜这与应用程序中的标志时间和服务器上存储的时间之间的时间差有关。
Option Explicit
Option Base 1
Sub LoopInFolder()
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Dim oa As Outlook.Application
Dim om As Outlook.MailItem
Dim m As Outlook.Namespace
Dim f As Outlook.Folder
Dim i As Object
Dim ws As Worksheet
Dim mcount As Byte
Dim mailboxes(1 To 3) As Variant
Set oa = New Outlook.Application
Set m = oa.GetNamespace("MAPI")
Set mailboxes(1) = 'folders
ThisWorkbook.Activate
mcount = 1
For Each ws In Worksheets
With ws
.Cells.Clear
.Activate
.Range("A1").Value = "Sender name"
.Range("B1").Value = "Mail title"
.Range("C1").Value = "Category"
.Range("D1").Value = "Processed by"
.Range("E1").Value = "Date received"
.Range("F1").Value = "Completed date"
.Range("A2").Activate
End With
For Each i In mailboxes(1).Items.Restrict("@SQL=%lastmonth(""http://schemas.microsoft.com/mapi/proptag/0x10910040"")%")
If i.Class = 43 Then
ActiveCell.Value = i.SenderName
ActiveCell.Offset(0, 1) = i.Subject
ActiveCell.Offset(0, 2) = i.Categories
ActiveCell.Offset(0, 3) = i.Categories
ActiveCell.Offset(0, 4) = i.ReceivedTime
ActiveCell.Offset(0, 5) = i.TaskCompletedDate
End If
ActiveCell.Offset(1, 0).Activate
Next
mcount = mcount + 1
Next
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
【问题讨论】:
-
要获得准确结果,请尝试使用 UTC stackoverflow.com/questions/48308994/… 的过滤器还有更多 docs.microsoft.com/en-us/office/vba/api/… 和 docs.microsoft.com/en-us/office/vba/api/…