I know this gets asked a lot but none of the solutions I have found seem to be working for me. I am trying to auto forward an email from a specific sender and with a specific subject to a list of new recipients. I'm also trying to change the subject and body of the email when forwarding. I have Outlook 365 and I am using the following VBA code which gives me no errors but it doesn't do anything... What am I doing wrong? Or is this code just outdated? Please help! TIA!
Public WithEvents objInbox As Outlook.Folder
Public WithEvents 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
Dim objForward As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
If (objMail.SenderEmailAddress = "sender@test.com") And (objMail.Subject = "Test") Then
Set objForward = objMail.Forward
With objForward
.Subject = "Custom Subject"
.HTMLBody = "<HTML><BODY>Type body here. </BODY></HTML>" & objForward.HTMLBody
.Recipients.Add ("recipient1@gmail.com")
.Recipients.Add ("recipient2@gmx.at")
.Recipients.ResolveAll
.Send
End With
End If
End If
End Sub
Public WithEvents objInbox As Outlook.Folder
Public WithEvents 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
Dim objForward As Outlook.MailItem
If TypeOf Item Is MailItem Then
Set objMail = Item
If (objMail.SenderEmailAddress = "sender@test.com") And (objMail.Subject = "Test") Then
Set objForward = objMail.Forward
With objForward
.Subject = "Custom Subject"
.HTMLBody = "<HTML><BODY>Type body here. </BODY></HTML>" & objForward.HTMLBody
.Recipients.Add ("recipient1@gmail.com")
.Recipients.Add ("recipient2@gmx.at")
.Recipients.ResolveAll
.Send
End With
End If
End If
End Sub