Assign Categories "Round Robin" style but in a shared mailbox but on specific emails only

Status
Not open for further replies.

reubendayal

Senior Member
Outlook version
Outlook 365 64 bit
Email Account
Office 365 Exchange
Hi All,

I am trying to auto assign categories to incoming emails. But these need to be applied on emails that match a certain criteria only for e.g. the sender's email address and a specific phrase in the subject line and the category applied to the email from the exchange server.

I need to assign these categories to those specific emails only, and these emails concern a specific case, but there are normally two emails that come per case and they usually arrive back to back. the categories I want to apply is basically to assign a team member's category color and this should follow a "round robin" or sequence style. So one case to team member "John" and the next 2 emails of the case to "Jane" and then back to john again and so on. Just so the workload is shared equally. The other problem is that the shared mailbox is used for general casework so there is a lot of emails that come to the mailbox. So I have now made a rule on the exchange server to assign a category "NewCase" to every new case email and also, to make a copy of it in a separate folder to keep track of whom the latest case was assigned to.

From the code on assigning categories "round robin" style from this page Use a Macro to Assign Messages in a Shared Mailbox I tried applying the VBA code in ThisOutlookSession using the GetFolderPath function, but that function has for some reason never worked for me. So I have now created a rule on my outlook client to run a script on incoming messages. And am trying to trigger the assigning of categories for the team from that script.

I have run in to several problems with the tweaked code I have so will not mess with that anyfurther, and would rather seek help.

At the moment I am able to get from the subfolder with the copy of the incoming case emails the category of whom the latest case was assigned. So to know whom should the new case emails in the inbox be assigned to. But I am quite clueless about where to go from there.

Please help!

Reuben
 
Hi All,

I am trying to auto assign categories to incoming emails. But these need to be applied on emails that match a certain criteria only for e.g. the sender's email address and a specific phrase in the subject line and the category applied to the email from the exchange server.

I need to assign these categories to those specific emails only, and these emails concern a specific case, but there are normally two emails that come per case and they usually arrive back to back. the categories I want to apply is basically to assign a team member's category color and this should follow a "round robin" or sequence style. So one case to team member "John" and the next 2 emails of the case to "Jane" and then back to john again and so on. Just so the workload is shared equally. The other problem is that the shared mailbox is used for general casework so there is a lot of emails that come to the mailbox. So I have now made a rule on the exchange server to assign a category "NewCase" to every new case email and also, to make a copy of it in a separate folder to keep track of whom the latest case was assigned to.

From the code on assigning categories "round robin" style from this page Use a Macro to Assign Messages in a Shared Mailbox I tried applying the VBA code in ThisOutlookSession using the GetFolderPath function, but that function has for some reason never worked for me. So I have now created a rule on my outlook client to run a script on incoming messages. And am trying to trigger the assigning of categories for the team from that script.

I have run in to several problems with the tweaked code I have so will not mess with that anyfurther, and would rather seek help.

At the moment I am able to get from the subfolder with the copy of the incoming case emails the category of whom the latest case was assigned. So to know whom should the new case emails in the inbox be assigned to. But I am quite clueless about where to go from there.

Please help!

Reuben
Hi All,

Further to the above, here's the code/script, I trigger using the rules in outlook. So as per the rule if the sender's email address, the specific subject text and the category colour already assigned from the exchange server start this script.

Code:
Public Sub ShowMessage(Item As Outlook.MailItem)

    Dim strCat As String
    Dim Sender As Outlook.AddressEntry
    Set Sender = Item.Sender

    Dim strMailboxName As String
    Dim MyFolder As Folder
    Dim myItems As Items
    Dim mItem As MailItem
    Dim e As Long
    Dim i As Integer
    
    
    strMailboxName = "SharedClients"
    Set MyFolder = Session.Folders(strMailboxName)
    Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

    Set myItems = MyFolder.Items
    myItems.Sort "ReceivedTime", True

    If myItems.Count > 0 Then
        Set mItem = myItems.Item(1)
        
        
        MsgBox MyFolder.FolderPath
        
        If mItem.Categories = "John; NewCase" Then
'        MsgBox "John Category"
            i = 2 'Call JaneShowMessage
        ElseIf mItem.Categories = "Jane St. Claire; NewCase" Then
'        MsgBox "Jane Category"
            i = 0 'Call JohnShowMessage
        Else
        MsgBox "Didnt work"
        End If
    
    End If

    If Item.Class = OlMail Then 'And Item.Categories = "NewCase" And Item.Sender = CE Global Maersk Immigration <maerskimmigration@deloittece.com> And Not Item.Categories = "John" Or Not Item.Categories = "Jane"
'    MsgBox "i count = " & i

'MsgBox "i value: " & i

    Select Case i
     Case 0
          strCat = "John"
     Case 1
          strCat = "John"
     Case 2
          strCat = "Jane"
     Case 3
          strCat = "Jane"
        
    End Select
    Item.Categories = Item.Categories & ";" & strCat
        Item.Save
    Err.Clear
     End If
     i = i + 1
     Debug.Print i
     MsgBox i
     If i = 4 Then i = 0

End Sub

The code calculates i = 2, as I have assigned John and NewCase on the latest email in the case initiations copy folder. But the case select bit of it, makes i = 3 and the code simply assigns the case emails in the inbox to "Jane" category. I do not know whether a for loop will solve the problem. Also, I am quite a novice with For loops, so cant put that code together.

Anyone that can help with this?

Thanks again.
 
code in ThisOutlookSession using the GetFolderPath function,
You only need the function if the mailbox is not your default data file. If you are using a shared exchange mailbox, you'd use different code.


With a rule, you need to have all actions in the script - add the category, copy the message.

I'm not sure what the sort and if statements is doing - when you use a rule, it applies to the message that triggers the rule. you don't need to find the messages.
Code:
    Set myItems = MyFolder.Items
    myItems.Sort "ReceivedTime", True
    If myItems.Count > 0 Then
        Set mItem = myItems.Item(1)

        MsgBox MyFolder.FolderPath

        If mItem.Categories = "John; NewCase" Then
'        MsgBox "John Category"
            i = 2 'Call JaneShowMessage
        ElseIf mItem.Categories = "Jane St. Claire; NewCase" Then
'        MsgBox "Jane Category"
            i = 0 'Call JohnShowMessage
        Else
        MsgBox "Didnt work"
        End If
    End If



Code:
Private Sub SetCatergoiesCopy(ByVal Item As Object)
    Dim strCat As String
    
    If Item.Class = olMail Then
    
    Select Case i
     Case 0
          strCat = "John"
     Case 1
          strCat = "John"
     Case 2
          strCat = "Jane"
     Case 3
          strCat = "Jane"
    End Select
        
    Item.categories = strCat
            Item.Save
        Err.Clear
     End If
     i = i + 1
     Debug.Print i
     If i = 4 Then i = 0

'now move a copy
strMailboxName = "SharedClients"
    Set MyFolder = Session.Folders(strMailboxName)
    Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

itemCopy = item.copy
itemcopy.move myfolder
 End Sub
 
You only need the function if the mailbox is not your default data file. If you are using a shared exchange mailbox, you'd use different code.


With a rule, you need to have all actions in the script - add the category, copy the message.

I'm not sure what the sort and if statements is doing - when you use a rule, it applies to the message that triggers the rule. you don't need to find the messages.
Code:
    Set myItems = MyFolder.Items
    myItems.Sort "ReceivedTime", True
    If myItems.Count > 0 Then
        Set mItem = myItems.Item(1)

        MsgBox MyFolder.FolderPath

        If mItem.Categories = "John; NewCase" Then
'        MsgBox "John Category"
            i = 2 'Call JaneShowMessage
        ElseIf mItem.Categories = "Jane St. Claire; NewCase" Then
'        MsgBox "Jane Category"
            i = 0 'Call JohnShowMessage
        Else
        MsgBox "Didnt work"
        End If
    End If



Code:
Private Sub SetCatergoiesCopy(ByVal Item As Object)
    Dim strCat As String
   
    If Item.Class = olMail Then
   
    Select Case i
     Case 0
          strCat = "John"
     Case 1
          strCat = "John"
     Case 2
          strCat = "Jane"
     Case 3
          strCat = "Jane"
    End Select
       
    Item.categories = strCat
            Item.Save
        Err.Clear
     End If
     i = i + 1
     Debug.Print i
     If i = 4 Then i = 0

'now move a copy
strMailboxName = "SharedClients"
    Set MyFolder = Session.Folders(strMailboxName)
    Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

itemCopy = item.copy
itemcopy.move myfolder
End Sub

Hi Diane,

Thank you for your reply.

I am sorry I wasn't clear in explaining the code and my plan with it.

It is correct that I am trying to make this script work on the shared mailbox as it is our team's common mailbox. So for proactively coloring the new case initiation emails, I have setup a rule on the OWA of the shared mailbox. So already when the email arrives from the server in to our outlook clients, the email comes with the NewCase color category. Also what I do is from another rule on the OWA I make a copy of the initiation emails to the "Copy of Initiations From Team" folder under the share mailbox's inbox.

Then once the initiation emails arrive in the shared mailbox, I am using the received time and IF statements at the beginning of the script to check from the "Copy of Initiations From Team" folder, by sorting it by date, and then taking the latest email (the first one from the of the list), and see who the last case was assigned to (John or jane). Thus giving "i" a value of 0 or 2. To then use thaa value and assign the correct category color on the subsequent new case initiations emails that come in. I couldn't think of another way of keeping track of whom the last case email was assigned to. Please feel free to suggest if this can be done in another way.

In the rule on the outlook client, I am only using the senders email, the subject line text and the "NewCase" category (already assigned from the OWA/server), to trigger the rule. And the only action I have in rule is to "Run a script". And then the rest is done via the script VBA.

I hope I have explained the issue better now.

p.s.: I have tried the steps on the Working with VBA and non-default Outlook Folders, but that too has not worked well for me. So a while someone had showed me this way of assigning the shared mailbox, and doing whatever with it:

strMailboxName = "SharedClients" Set MyFolder = Session.Folders(strMailboxName) Set MyFolder = MyFolder.Folders("Inbox").Parent.Folders("Copy of Initiations From Team")

Thanks again.
 
Then once the initiation emails arrive in the shared mailbox, I am using the received time and IF statements at the beginning of the script to check from the "Copy of Initiations From Team" folder, by sorting it by date, and then taking the latest email (the first one from the of the list), and see who the last case was assigned to (John or jane). Thus giving "i" a value of 0 or 2. To then use thaa value and assign the correct category color on the subsequent new case initiations emails that come in. I couldn't think of another way of keeping track of whom the last case email was assigned to. Please feel free to suggest if this can be done in another way.
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
 
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
That would be great!

I look forward to hearing from you.

One issue I noticed with my idea of proactively making the copy of the new case initiation emails from the OWA over to the "Copy of Initiations From Team" folder is that those emails will never get the color categories of the team, and just have the New Case category. So your suggestion of moving a copy of the processed email at the end of the script is the correct way to resolve that problem.
 
That would be great!

I look forward to hearing from you.

One issue I noticed with my idea of proactively making the copy of the new case initiation emails from the OWA over to the "Copy of Initiations From Team" folder is that those emails will never get the color categories of the team, and just have the New Case category. So your suggestion of moving a copy of the processed email at the end of the script is the correct way to resolve that problem.

Hi Diane,

May I gently check with you if you have had a chance to test the code out?

Thank you.
 
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
Hi Diane,

Sorry to chase you but have you had a chance to test the code or suggest a change in the code?

Thank you.
 
The only other way would be to write the last assigned to the registry and read - but your method is probably just as easy. I'll need to test the macro and see what its doing.
Hi Diane,
Have you had a chance to test the macro?
Thank you.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Z Outlook 365 Automatically assign categories to incoming mail in a shared folder Round Robin Outlook VBA and Custom Forms 1
D Assign categories to outgoing emails Outlook VBA and Custom Forms 0
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
P Auto assign shared mailbox Outlook VBA and Custom Forms 1
F How to assign a task to a public task folder? Using Outlook 1
A How to assign the value returned by the regex execute function to a variable? Using Outlook 1
soadfan assign category (VBA) Using Outlook 7
Diane Poremsky Assign one task to several people Using Outlook 0
Diane Poremsky Assign an Email Account to an Outlook Contact Using Outlook 0
E for Mac: Assign Task not available!? Using Outlook 1
E Outlook VBA to print attached Pdf to a fax printer and assign fax number Using Outlook 0
A Assign a unique number to every message I send Using Outlook 0
Z assign unique number email Using Outlook 8
J Assign a signature by external or internal reciepents. Outlook VBA and Custom Forms 1
P VBA to assign category on calendar item does not work ?? why ?? Outlook VBA and Custom Forms 5
S assign task programmatically Outlook VBA and Custom Forms 2
C Cannot assign a task from a public folder? Outlook VBA and Custom Forms 4
C Assign To and CC list while using Redemption.dll library Outlook VBA and Custom Forms 10
C How to assign icon to a button in Outlook Add-in Outlook VBA and Custom Forms 1
V VBA Categories unrelated to visible calendar and Visual appointment Categories Outlook VBA and Custom Forms 2
P How to add a column named categories when searching in Outlook Using Outlook 0
S Folder Pane Colour Categories Using Outlook 6
Ken Pascoe Outlook Categories Quick List Using Outlook 0
O Calendar - appointment templates and categories Using Outlook 1
T Increasing the number of items that appear on the Categories list Using Outlook 2
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
Z How to show concatenated categories in list task view? Using Outlook 2
D Importing Outlook Categories from another domain (Exchange 2016/Outlook 2016) Using Outlook 4
S Conditional formatting problem with "is not empty" and categories Using Outlook 2
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
P how to remove unwanted PST file default categories assigned to many calendar entries Using Outlook 7
P Import Categories from Outlook 2003 Using Outlook 8
A Outlook reverse categories Outlook VBA and Custom Forms 1
Mark Foley Color Categories on IMAP mail lost when installing new Windows 7 workstation Using Outlook 12
B VBA Macro for assigning multiple Categories to an email in my Inbox Outlook VBA and Custom Forms 1
P Task Categories Using Outlook 2
I categories for outgoing email Outlook VBA and Custom Forms 7
S Appointment-Cannot set Categories because ConversationID is not set Outlook VBA and Custom Forms 1
M Using conditional formatting on a shared calendar with categories Using Outlook 6
S Appointment colour categories disappear Using Outlook 4
Z Outlook.com Contact categories Using Outlook 8
A Are categories still recommended for creating local distribution lists? Using Outlook 3
Diane Poremsky Using Categories for Dynamic Distribution Lists Using Outlook 0
Diane Poremsky Printing Calendars with Color Categories Using Outlook 0
avant-guvnor Outlook 2016 and views, categories etc. Using Outlook 3
T categories in Outlook 2016 Using Outlook 0
makinmyway How to Easily/Quickly Ungroup by Categories Using Outlook 1
C Printing tasks with multiple categories Using Outlook 5
Mark Foley Where are Outlook categories save for IMAP? Using Outlook 12
M Trouble using keyboard shortcut for color categories in Outlook 2016 Using Outlook 3

Similar threads

Back
Top