• Multiple Category macro

    Author
    Topic
    #461702

    Howdy,

    I use macros to organise and sort (via search folders) my rather large inbox. I have previously received advice on how to create a macro to assign a single category to an email. I assign the macro to a custom toolbar button and use the combination of categories and flags organise the emails.

    It would be really handy to be able assign multiple categories (one after the other rather than multiple via one button), eg ‘category-topic’ and ‘category-file’.

    Can anyone help me out with this in VBA code (if not I will need to default to pulling up the category window and assigning multiple categories).

    The original code provided was….

    —————————————————————
    Sub SetCategoryTest()
    Dim collSelItems As Collection
    Dim lngC As Long
    Set collSelItems = GetSelectedItems
    If Not collSelItems Is Nothing Then
    For lngC = 1 To collSelItems.Count
    collSelItems(lngC).Categories = “Test”
    collSelItems(lngC).Save
    Next lngC
    End If
    Set collSelItems = Nothing
    End Sub

    —————————————————————

    Viewing 0 reply threads
    Author
    Replies
    • #1172443

      You can specify multiple category as a list separated by comma+space:

      collSelItems(lngC).Categories = “category-topic, category-file”

      • #1175219

        You can specify multiple category as a list separated by comma+space:

        collSelItems(lngC).Categories = “category-topic, category-file”

        Hi Hans, Thanks for your answer. I was wondering if there is a method of ‘adding’ to a previously assigned category rather than doing multiple categories as you have presented above. Apologies if I wasn’t clear in my earlier request.

        Thanks – Claude

        • #1175220

          You can add a category to the already assigned categories as follows:

          Code:
          If collSelItems(lngC).Categories = "" Then
            collSelItems(lngC).Categories = "my category"
          Else
            collSelItems(lngC).Categories = collSelItems(lngC).Categories & ", my category"
          End If
          • #1175288

            You can add a category to the already assigned categories as follows:

            Code:
            If collSelItems(lngC).Categories = "" Then
              collSelItems(lngC).Categories = "my category"
            Else
              collSelItems(lngC).Categories = collSelItems(lngC).Categories & ", my category"
            End If

            Hi Hans,

            See the code below…I hope I have interpreted your instructions correctly? Unfortunately, I get an ‘run time 9 , subscript out of range’ error when I try to run the macro:

            Sub SetCategoryP0429()
            Dim collSelItems As Collection
            Dim lngC As Long
            Set collSelItems = GetSelectedItems
            If collSelItems(lngC).Categories = “” Then
            collSelItems(lngC).Categories = “P0429”
            Else
            collSelItems(lngC).Categories = collSelItems(lngC).Categories & “, P0429”
            End If

            Set collSelItems = Nothing
            End Sub

            Can you advise how to fix this?

            Cheers,

            Claude

            • #1175296

              If you compare this with the original version, you’ll see that you have forgotten to include the lines

              If Not collSelItems Is Nothing Then
              For lngC = 1 To collSelItems.Count

              and

              collSelItems(lngC).Save
              Next lngC
              End If

    Viewing 0 reply threads
    Reply To: Multiple Category macro

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: