Log in

View Full Version : Change subject and forward emails sitting in a folder (inbox)



Galego
07-12-2018, 01:45 AM
Hello good morning/afternoon/evening/night

I want a Macro for all emails sitting in Folder "output" under my inbox to change the subject and forward them to an email address.

So far I have this code (found in internet) and returns with an error: "run time -2147221223 (80040119) - The Operation failed because of a registry or installation problem."

Can anyone please help me?

Thanks.

gmayor
07-12-2018, 04:00 AM
This is quite straightforward using an Outlook macro e.g.


Sub ChangeSubjectThenForward()
Dim olFolder As Folder
Dim oItem As Object
Dim olMsg As MailItem
Set olFolder = Session.GetDefaultFolder(olFolderInbox).folders("output") 'note the folder name is case sensitive!

For Each oItem In olFolder.Items
If TypeName(oItem) = "MailItem" Then
oItem.Subject = "The New Subject"
oItem.Save
Set olMsg = oItem.Forward
olMsg.Recipients.Add "someone@somewhere.com" 'the address of the person you are forwarding to
olMsg.Send
End If
Next oItem
lbl_Exit:
Set olFolder = Nothing
Set oItem = Nothing
Set olMsg = Nothing
Exit Sub
End Sub