【问题标题】:How do you specify a flagged item in Outlook with Excel VBA?如何使用 Excel VBA 在 Outlook 中指定标记的项目?
【发布时间】:2017-04-26 18:17:33
【问题描述】:

我正在尝试计算我的 Outlook 文件夹中有多少电子邮件。问题是它正在计算“标记”项目,我需要代码来跳过任何“标记”项目。

我已尝试在以下代码的第 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

【问题讨论】:

标签: excel vba outlook excel-2010 outlook-2010


【解决方案1】:

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("0m3r@email.com") ' 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 methodFindNext method 迭代集合中特定项目的替代方法。如果项目数量较少,Find or FindNext methods 比过滤更快。如果集合中有大量项目,则 Restrict 方法的速度明显更快,尤其是在预计只能找到大型集合中的少数项目的情况下。
_


Filtering Items Using a String Comparison DASL 过滤器 支持包括等价、前缀、短语和子字符串匹配。请注意,当您对 Subject 属性进行过滤时,会忽略 "RE: ""FW: " 等前缀。


【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多