question

mike-3152 avatar image
0 Votes"
mike-3152 asked mike-3152 answered

Using VBA to copy email to a different folder

I seem to have this almost working but it is sending 3 (and sometimes more) copies to the folder instead of just one. It is the last IF statement that I have changed., the one referencing: "PO Send to Kathy". All the others are for simply moving the email. But for this case I want to leave the email and just send a copy but the problem is, it is sending at multiple copies to that folder each time.


Here is the the code with the copy part added: Set objMail = objMail.Copy. Prior to that it was just with the move statement. Again, it does work, it just makes multiple copies. Any help would be appreciated. Thanks


 'Occurs when changing item
 Private Sub objInboxItemsOrder_ItemChange(ByVal Item As Object)
     Dim objMail As Outlook.MailItem
     Dim objTargetFolder As Outlook.Folder
     
     If TypeOf Item Is MailItem Then
        Set objMail = Item
        'Move mails based on color category
        If InStr(objMail.Categories, "Karen") > 0 Then
           Set objTargetFolder = Application.Session.Folders("orders@xxs.com").Folders("Karen")
           objMail.Move objTargetFolder
         ElseIf InStr(objMail.Categories, "Quote") > 0 Then
           Set objTargetFolder = Application.Session.Folders("orders@xxx.com").Folders("Quote")
           objMail.Move objTargetFolder
         ElseIf InStr(objMail.Categories, "PO Keep Here") > 0 Then
           Set objTargetFolder = Application.Session.Folders("orders@xxx.com").Folders("Purchase Order")
           objMail.Move objTargetFolder
         ElseIf InStr(objMail.Categories, "PO Send to Kathy") > 0 Then
           Set objTargetFolder = Application.Session.Folders("orders@xxx.com").Folders("PO Send to Kathy")
           Set objMail = objMail.Copy
           objMail.Move objTargetFolder
        End If
     End If
 End Sub




office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TvanStiphout avatar image
0 Votes"
TvanStiphout answered

That would lead me to think the code is in the wrong event.
The ItemAdd event of the Folder object comes to mind.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

mike-3152 avatar image
0 Votes"
mike-3152 answered

Thanks for the suggestion. I will try that and report back but it seems like if the item is the the email, we are changing it by assigning a category. That, I believe, is the trigger to the event?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.