• Macro to Assign Category (2003)

    Author
    Topic
    #437312

    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?

    Viewing 0 reply threads
    Author
    Replies
    • #1039192

      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.

      • #1039942

        Thanks Hans – worked a treat.

      • #1043841

        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

        • #1043842

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

          • #1043843

            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.

            • #1043844

              Try using

              ActiveExplorer.Selection.Item(1)

              instead of

              ActiveInspector.CurrentItem

            • #1043898

              (Edited by JohnBF on 18-Dec-06 09:55. Code corrections)

              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

            • #1043941

              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

            • #1043944

              The correct syntax is

              If Not collSellItems Is Nothing Then

            • #1043949

              stupidme Thanks, Hans. I’ll correct the post for any later Loungers.

            • #1043945

              Hi Claude,
              Try this amendment:

              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
              

              HTH

            • #1043946

              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.

            • #1043947

              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

            • #1043997

              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. crossfingers

    Viewing 0 reply threads
    Reply To: Macro to Assign Category (2003)

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

    Your information: