Results 1 to 15 of 15
  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

    Macro to Assign Category (2003)

    Hi, I would like to assign a category (already put in Master List) via a macro button on a customised toolbar. I know how to create a toolbar button assigned to a macro, however I dont know how to write VBA code to assign the category. Is this possible?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to Assign Category (2003)

    If you want to assign a specific category:

    Sub SetCategory()
    If Inspectors.Count > 0 Then
    ActiveInspector.CurrentItem.Categories = "MyCategory"
    End If
    End Sub

    If you want to show the Categories dialog, see JohnBF's <post:=549,323>post 549,323</post:>.

  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

    Re: Macro to Assign Category (2003)

    Thanks Hans - worked a treat.

  4. #4
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to Assign Category (2003)

    Hans,

    FOr some reason the Macro's dont work anymore. I am a bit confiused because I am sure they worked initially. When I first try to use the macro after logging on outlook asks if I want to 'enable macros' which I say 'yes'. Even, the open categories dialogue box does not open anymore?? I have attached a couple of the macros which I am sure replicate those that you recommended. Any ideas on the problem? Thanks.

    Sub SetCategoryIAC()
    If Inspectors.Count > 0 Then
    ActiveInspector.CurrentItem.Categories = "IAC"
    End If
    End Sub

    Sub ShowCategoriesDialog()
    If Inspectors.Count Then
    With ActiveInspector.CurrentItem
    If .Class = olMail Then .ShowCategoriesDialog
    End With
    End If
    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to Assign Category (2003)

    There is nothing wrong with the macros. Are you sure you have an e-mail open when you try to run the macros?

  6. #6
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to Assign Category (2003)

    Hans - the advice that I have to have the email 'open' was the trick - thankyou. Do you know if there is a way to assign categories without having the mail item actually open, ie assigning a category when you have the mail item highlighted and are reading it in the preview pane?

    Once again thanks for the fast response.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to Assign Category (2003)

    Try using

    ActiveExplorer.Selection.Item(1)

    instead of

    ActiveInspector.CurrentItem

  8. #8
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to Assign Category (2003)

    Edited by HansV to crop huge screenshot to show only the relevant part

    Thanks John, the code sound intriguing (for someone who likes tools but does not understand VBA!). I tried to establish a test case but came up with an error (refer to attached).

    Can you please give me any hints on how I may have incorporated it incorrectly. Thanks

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to Assign Category (2003)

    The correct syntax is

    If Not collSellItems Is Nothing Then

  10. #10
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Macro to Assign Category (2003)

    Hi Claude,
    Try this amendment:
    <pre>Sub SetCategory()
    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 = "MyCategory"
    Next lngC
    End If
    Set collSelItems = Nothing
    End Sub
    </pre>


    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  11. #11
    2 Star Lounger
    Join Date
    Feb 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    114
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro to Assign Category (2003)

    Thanks all for helping me out. The code now works, however I am a little confused what the code adds. I tried selecting multiple items in the explorer pane to see if set categories to multiple items (ie what I understood from John's "...of all selected items in explorer pane..") but it still only adjusted one email item. To my understanding, this is the same function as the previous code.

    I am interested to understand what the code does/add when you have time, and helped out a few other people with potentially higher priority problems.....

    Thanks again.

  12. #12
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Macro to Assign Category (2003)

    <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30> Thanks, Hans. I'll correct the post for any later Loungers.
    -John ... I float in liquid gardens
    UTC -7ąDS

  13. #13
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Macro to Assign Category (2003)

    Claude,
    John's code should set the category for all the selected items in the current folder, unless you have an item open in the active window, in which case it will only set the category for that item.
    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  14. #14
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Macro to Assign Category (2003)

    <P ID="edit" class=small>(Edited by JohnBF on 18-Dec-06 09:55. Code corrections)</P>If you want the flexibility of all selected items in the explorer pane, or the current open item, add this function to your code (I use it for all kinds of little macro thingies in Outlook):

    Public Function GetSelectedItems() As Collection
    Dim lngC As Long
    Set GetSelectedItems = New Collection
    If TypeName(Outlook.ActiveWindow) = "Explorer" Then
    For lngC = 1 To ActiveExplorer.Selection.Count
    GetSelectedItems.Add Outlook.ActiveExplorer.Selection(lngC)
    Next lngC
    Else
    GetSelectedItems.Add Outlook.ActiveInspector.CurrentItem
    End If
    End Function

    Then modify Hans
    -John ... I float in liquid gardens
    UTC -7ąDS

  15. #15
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Macro to Assign Category (2003)

    Claude, in addition to the syntax error Hans noted, I fixed an omission in the code - I added an Item.Save command. Try it now. <img src=/S/crossfingers.gif border=0 alt=crossfingers width=17 height=16>
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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