Consulting

Results 1 to 2 of 2

Thread: Categories Help

  1. #1
    VBAX Newbie
    Joined
    May 2014
    Posts
    2
    Location

    Categories Help

    Hi all,

    I am currently using categories for prioritising my work. Using names 1, 2, 3, 4 and so on to 10. I know it should be possible but due to my lack of knowledge in Outlook and Outlook relevant code. I am wanting to run a macro every time I finish a job so that it will change all categories down one number. eg 2 becomes 1 and 7 becomes 6. Each category could have any number of emails assigned to it.

    Thanks in advance.

    Z

    If possible can you please explain what you have done so I can get closer to understanding what is going on.

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try something like this:

    Sub Reset_Categories()
    
    Dim fldrItems As Items
    Dim itm As Object
    Dim i As Long
    
    Set fldrItems = Session.GetDefaultFolder(olFolderInbox).Items
    
    For Each itm In fldrItems
        If itm.Categories = "1" Then
            itm.Categories = "Complete"
            itm.Save
        End If
    Next itm
    
        For i = 2 To 10
        'Debug.Print "Processing old category: " & i
            
            For Each itm In fldrItems
                If itm.Categories = CStr(i) Then
                    'Debug.Print itm.Subject
                    itm.Categories = CStr(i - 1)
                    'Debug.Print " - " & i & " changed to " & i - 1
                    itm.Save
                End If
            Next itm
        
        Next I
    
    ExitRoutine:
        Set fldrItems = Nothing
        Set itm = Nothing
        
    'Debug.Print "Done."
    
    End Sub
    You can see what is happening by stepping through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    You will note it is inefficient, processing every item 10 times. See here http://www.jpsoftwaretech.com/use-fi...outlook-macros for a way to target the items with the category you want to update.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Posting Permissions

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