简体   繁体   中英

Outlook VBA for Assigning Work with Categories on Selected Emails

I'm looking for a way to assign work (emails) with the help of outlook categories to my team members however I have to do that manually considering I have 2000 emails daily this is a huge task too attend , I am trying to achieve the below

1) assign 3 emails to each team member 2) assignment on only selected emails and not the entire mailbox 3) assignment in order of oldest to newest emails. 4) assignment to be done as per the below requirement ie

if 10 emails are selected the distribution should look like emails ie 1,2,3 to agent 1, email ie 4,5,6 to agent 2, email ie 7,8,9 to agent 3 and email ie 10 to agent 4 and loop stops here.

Sub EmailCategories()
Dim strCat As String
Dim olmail As MailItem
'If Item.Class = olmail Then
'For i = 0 To 2

For Each olmail In Outlook.Application.ActiveExplorer.Selection
'olmail.Categories = "Agent - 1"

Select Case i
Case 0
olmail.Categories = "Agent - 1"
Case 1
olmail.Categories = "Agent - 2"
Case 2
olmail.Categories = "Agent - 3"
Case 3
olmail.Categories = "Agent - 4"
Case 4
olmail.Categories = "Agent - 5"
Case 5
olmail.Categories = "Agent - 6"
End Select

'Item.Categories = mailMsg
olmail.Item.Save
Err.Clear

Next
'End If
i = i + 3
Debug.Print i
If i = 5 Then
i = 0
End If
End Sub

I have finally cracked the solution so sharing the same as below, thank you.

Sub category_assigment()
Dim oOutlook As Object: Dim oExplorer As Object
Dim i As Long: Set oOutlook = CreateObject("Outlook.Application")
Dim objSelection As Outlook.Selection
Dim Result As Integer
Set objSelection = Application.ActiveExplorer.Selection

Set oExplorer = oOutlook.ActiveExplorer: Dim oSelection As Object
Set oSelection = oExplorer.Selection
Dim oCategory As String
'For i = 1 To oSelection.Count
On Error Resume Next
For i = oSelection.Count To 1 Step -1
If oSelection.Item(i).Categories = "" Then
For x = 0 To 15
If x = 0 Then
oCategory = "Agent 1"
ElseIf x = 3 Then
oCategory = "Agent 2"
ElseIf x = 6 Then
oCategory = "Agent 3"
ElseIf x = 9 Then
oCategory = "Agent 4"
ElseIf x = 12 Then
oCategory = "Agent 5"
ElseIf x = 15 Then
oCategory = "Agent 6"
Else: GoTo Line01
End If
For y = 0 To 2
If oSelection.Item(i - x - y).Categories = "" Then
oSelection.Item(i - x - y).Categories = oCategory
oSelection.Item(i - x - y).Save
End If
Next
Line01:
Next
End If
Next i

Result = MsgBox("Total Emails Assigned : " & _
            objSelection.Count, vbInformation, "Selected Items")

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM