如何删除所有颜色类别?

发布于 2025-01-03 14:07:44 字数 689 浏览 6 评论 0原文

我正在尝试删除所有颜色类别。但是,以下代码并不总是删除所有案例,通常会留下两个或三个案例。

它有什么理由跳过某些类别吗?

    Public Sub DeleteAllCategories()
        On Error GoTo MyErrorHandler

        'Assume gOutlookApp (as in Dim gOutlookApp As Outlook.Application) is valid
        Dim theCategories As Outlook.Categories
        Set theCategories = gOutlookApp.Session.Categories

        Dim i As Long
        For i = 1 To theCategories.Count
            theCategories.Remove 1
            DoEvents
        Next

        Exit Sub

    MyErrorHandler:
        MsgBox "DeleteAllCategories" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
    End Sub

I'm trying to delete all the color categories. However, the following code doesn't always delete all cases, typically leaving two or three.

Any reason it'd skip some categories?

    Public Sub DeleteAllCategories()
        On Error GoTo MyErrorHandler

        'Assume gOutlookApp (as in Dim gOutlookApp As Outlook.Application) is valid
        Dim theCategories As Outlook.Categories
        Set theCategories = gOutlookApp.Session.Categories

        Dim i As Long
        For i = 1 To theCategories.Count
            theCategories.Remove 1
            DoEvents
        Next

        Exit Sub

    MyErrorHandler:
        MsgBox "DeleteAllCategories" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
    End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年 2025-01-10 14:07:45

这个问题有点老了,但是对于可能正在寻找相同答案的其他人......

请尝试以下操作:

Public Sub DeleteAllCategories()
    'Assume gOutlookApp (as in Dim gOutlookApp As Outlook.Application) is valid
    Dim objCategory As Outlook.Category   'Changed from Outlook.Categories
    Dim strCAT As String
    On Error GoTo MyErrorHandler

    For Each objCategory In Session.Categories 'Removed the gOutlookApp
        strCAT = objCategory
        Debug.Print strCAT;
        Session.Categories.Remove (strCAT)
        Debug.Print " - Deleted: " & CBool(Session.Categories.Item(strCAT) Is Nothing)
    Next

    Exit Sub

MyErrorHandler:
    MsgBox "DeleteAllCategories" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
End Sub

This question is a little old, but for someone else who may be searching for the same answer...

Give the below a try:

Public Sub DeleteAllCategories()
    'Assume gOutlookApp (as in Dim gOutlookApp As Outlook.Application) is valid
    Dim objCategory As Outlook.Category   'Changed from Outlook.Categories
    Dim strCAT As String
    On Error GoTo MyErrorHandler

    For Each objCategory In Session.Categories 'Removed the gOutlookApp
        strCAT = objCategory
        Debug.Print strCAT;
        Session.Categories.Remove (strCAT)
        Debug.Print " - Deleted: " & CBool(Session.Categories.Item(strCAT) Is Nothing)
    Next

    Exit Sub

MyErrorHandler:
    MsgBox "DeleteAllCategories" & vbCrLf & vbCrLf & "Err = " & Err.Number & vbCrLf & "Description: " & Err.Description
End Sub
没有心的人 2025-01-10 14:07:45

我设法使用规则来做到这一点。就像如果它分配给任何类别然后删除类别,然后我在收件箱上运行它。如果您感兴趣的话,可以使用非编码解决方案!

I managed to do this using a rule. Something like if its assigned to any category then remove category, and then I ran it on my inbox. A non-coded solution if that interests you!

濫情▎り 2025-01-10 14:07:45

删除时反向循环

Option Explicit
Public Sub DeleteAllCategories()
    Dim theCategories As Outlook.Categories
    Set theCategories = Application.Session.Categories

    Dim i As Long
    For i = theCategories.Count To 1 Step -1
        DoEvents
        Debug.Print theCategories(i)
'       Remove i
    Next
End Sub

Reverse loop when deleting

Option Explicit
Public Sub DeleteAllCategories()
    Dim theCategories As Outlook.Categories
    Set theCategories = Application.Session.Categories

    Dim i As Long
    For i = theCategories.Count To 1 Step -1
        DoEvents
        Debug.Print theCategories(i)
'       Remove i
    Next
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文