stripesandcanvas
Member
- Outlook version
- Outlook 365 64 bit
- Email Account
- Office 365 Exchange
Hi, I have a VBA script that auto-forwards one set of conditions to a group of people. I want to add another set of conditions so that it auto-forwards a different email to another group of people so that the script sends email 1 to group A and email 2 to group B. I'm having difficulty getting the second set of conditions to work. How can I get this to work? Ultimately I'd like to have 5 or so of different set of conditions. Setting up Outlook rules doesn't work due to auto-forwarding limitations.
Here is what I have so far:
Public WithEvents objInbox As Outlook.Folder
Public With Events objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInbox = Outlook.Application.Session.GetDefaultFolder (olFolderInbox)
Set objInboxItems = objInbox.Items
End Sub
Private Sub objInboxItems_ItemAdd (ByVal Item As Object)
Dim objMail As Outlook.MailItem
Fim objForward As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
If (objMail.SenderEmailAdress = "sender@mailbox.com) And (objMail.Subject = "Email Subject 1") Then
Set objForward = objmail.Forward
With obJForward
.Subject = "Email Subject 1"
.Recipients.Add ("person1@mailbox.com")
.Recipients.Add ("person2@mailbox.com")
.Recipients.ResolveAll
.Send
End With
End If
End If
End Sub
'Until here it works, can't get the below part to work
Private Sub objInboxItems_ItemAdd_2 (ByVal Item As Object)
Dim objMail As Outlook.MailItem
Fim objForward As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
If (objMail.SenderEmailAdress = "sender@mailbox.com) And (objMail.Subject = "Email Subject 2") Then
Set objForward = objmail.Forward
With obJForward
.Subject = "Email Subject 2"
.Recipients.Add ("person3@mailbox.com")
.Recipients.Add ("person4@mailbox.com")
.Recipients.ResolveAll
.Send
End With
End If
End If
End Sub
Here is what I have so far:
Public WithEvents objInbox As Outlook.Folder
Public With Events objInboxItems As Outlook.Items
Private Sub Application_Startup()
Set objInbox = Outlook.Application.Session.GetDefaultFolder (olFolderInbox)
Set objInboxItems = objInbox.Items
End Sub
Private Sub objInboxItems_ItemAdd (ByVal Item As Object)
Dim objMail As Outlook.MailItem
Fim objForward As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
If (objMail.SenderEmailAdress = "sender@mailbox.com) And (objMail.Subject = "Email Subject 1") Then
Set objForward = objmail.Forward
With obJForward
.Subject = "Email Subject 1"
.Recipients.Add ("person1@mailbox.com")
.Recipients.Add ("person2@mailbox.com")
.Recipients.ResolveAll
.Send
End With
End If
End If
End Sub
'Until here it works, can't get the below part to work
Private Sub objInboxItems_ItemAdd_2 (ByVal Item As Object)
Dim objMail As Outlook.MailItem
Fim objForward As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
If (objMail.SenderEmailAdress = "sender@mailbox.com) And (objMail.Subject = "Email Subject 2") Then
Set objForward = objmail.Forward
With obJForward
.Subject = "Email Subject 2"
.Recipients.Add ("person3@mailbox.com")
.Recipients.Add ("person4@mailbox.com")
.Recipients.ResolveAll
.Send
End With
End If
End If
End Sub