如何在Outlook中使用Excel VBA指定标记的项目?
问题描述:
我想知道我的Outlook文件夹中有多少封电子邮件。问题是它正在计数“已标记”项目,我需要代码跳过任何“已标记”项目。如何在Outlook中使用Excel VBA指定标记的项目?
我已经尝试使用下面的代码行18上的“olNoFlag”属性,但它不会工作。谁能帮我这个?我很亲密!
Sub LoopFoldersInNoctalkSW()
Dim ns As Object
Dim objFolder As Object
Dim objSubfolder As Object
Dim lngCounter As Long
Dim olNoFlag As Object
Set ns = GetObject("", "Outlook.Application").GetNamespace("MAPI")
Set objFolder = ns.Folders("NoctalkSW")
For Each objSubfolder In objFolder.Folders
On Error Resume Next
With Worksheets("Folder Names 2")
lngCounter = lngCounter + 1
.Cells(lngCounter, 1) = objSubfolder.Name
.Cells(lngCounter, 2) = objSubfolder.Items.Count
.Cells(lngCounter, 3) = objSubfolder.Items.GetLast.ReceivedTime
End With
Debug.Print objSubfolder.Name
Debug.Print objSubfolder.Items.Count
Debug.Print objSubfolder.Items.GetLast.ReceivedTime
Next objSubfolder
End Sub
答
与Items.Restrict Method (Outlook)工作,以排除标志项目由Filtering Items Using a String Comparison
Filter = "@SQL=" & " Not " & _
"http://schemas.microsoft.com/mapi/proptag/0x10900003" & _
"" & "=1"
代码示例
Option Explicit
Const olFolderInbox = 6
Sub HowManyEmails()
Dim olApp As Object
Dim olNs As Object
Dim Inbox As Object
Dim SubFolder As Object
Dim Recip As Object
Dim Items As Object
Dim Filter As String
Set olApp = CreateObject("Outlook.Application")
Set olNs = olApp.GetNamespace("MAPI")
Set Recip = olNs.CreateRecipient("[email protected]") ' Share address
Recip.Resolve
Set Inbox = olNs.GetSharedDefaultFolder(Recip, olFolderInbox) ' Inbox
Filter = "@SQL=" & " Not " & _
"http://schemas.microsoft.com/mapi/proptag/0x10900003" & _
"" & "=1"
Set Items = Inbox.Items.Restrict(Filter) ' filter inbox items
'// Print on Immediate Window
Debug.Print Inbox.Name & " Has " & Items.Count & " Items "
For Each SubFolder In Inbox.Folders
Set Items = SubFolder.Items.Restrict(Filter) ' filter sub items
'// Print on Immediate Window
Debug.Print SubFolder.Name & " Has " & Items.Count & " Items "
Next
Set olApp = Nothing
Set olNs = Nothing
Set Inbox = Nothing
Set SubFolder = Nothing
Set Recip = Nothing
End Sub
Items.Restrict Method将过滤器应用于Items集合,返回包含所有项目从匹配过滤,原来的一个新的集合。
该方法是使用Find method或FindNext method遍历集合中的特定项目的替代品。如果有少量项目,则过滤比过滤更快。如果集合中有大量项目,Restrict方法会显着加快,特别是如果预计可以找到大集合中的少数项目。 _
Filtering Items Using a String Comparison该DASL滤波器支持包括等价,前缀,短语和子串匹配。请注意,当您在主题属性上筛选时,将忽略诸如“RE:”和“FW:”的前缀。
的可能的复制[计数使用Excel VBA跟进电子邮件](http://*.com/questions/25922611/count-followup-emails-using-excel-vba) –