如何在带有Excel VBA的Outlook中指定已标记的项目? [英] How do you specify a flagged item in Outlook with Excel VBA?

查看:209
本文介绍了如何在带有Excel VBA的Outlook中指定已标记的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试计算Outlook文件夹中的电子邮件数量.问题是它正在计数已标记"项目,我需要代码来跳过任何已标记"项目.

I'm trying to get a count of how many emails are in my Outlook folders. The problem is that it is counting the "Flagged" items and I need the code to skip any item that is "Flagged".

我尝试在下面的代码的第18行上使用"olNoFlag"属性,但是它将无法正常工作.谁能帮我这个?我太近了!

I've tried using the "olNoFlag" property on line 18 of the below code but it won't work. Can anyone help me with this? I'm so close!

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

推荐答案

使用


代码示例

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方法 将过滤器应用于Items集合,并返回一个新集合,其中包含来自原始对象的所有与该过滤器匹配的所有项目.
该方法是使用 查找方法的替代方法 FindNext方法 来遍历集合中的特定项目. 查找或FindNext方法 如果项目数量较少,则比过滤速度要快.如果集合中有大量项目,则Restrict方法的速度会大大提高,尤其是在预期只能在大型集合中找到少量项目的情况下.
_

Items.Restrict Method Applies a filter to the Items collection, returning a new collection containing all of the items from the original that match the filter.
The method is an alternative to using the Find method or FindNext method to iterate over specific items within a collection. The Find or FindNext methods are faster than filtering if there are a small number of items. The Restrict method is significantly faster if there is a large number of items in the collection, especially if only a few items in a large collection are expected to be found.
_

使用字符串比较来过滤项目 DASL 过滤器支持的过滤包括等价,前缀,词组和子字符串匹配.请注意,当您对Subject属性进行过滤时,诸如"RE:" "FW:" 之类的前缀将被忽略.

Filtering Items Using a String Comparison that DASL filters support includes equivalence, prefix, phrase, and substring matching. Note that when you filter on the Subject property, prefixes such as "RE: " and "FW: " are ignored.

这篇关于如何在带有Excel VBA的Outlook中指定已标记的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆