Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

    ---------------------------------------------------------------

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can specify multiple category as a list separated by comma+space:

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

  3. #3
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='787736' date='06-Aug-2009 11:12']You can specify multiple category as a list separated by comma+space:

    collSelItems(lngC).Categories = "category-topic, category-file"[/quote]

    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

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

  5. #5
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='790960' date='27-Aug-2009 14:38']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
    [/quote]

    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

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •