PDA

View Full Version : script for outlook - append text to subject - forward to email address - move to fold



Symbiot
07-31-2013, 09:30 AM
Hi

I am hoping you can help me.. I want to create a script that does the following based on a rule I setup in outlook.. so when the rule finds a match for it's parameters it runs the script:

1. append some text to the subject but don't change the original email subject.
2. forward the email to another email address.
3. Deletes the sent message
4. moves the message to a defined folder..


I have been looking at this snippet:


Sub ForwardEmail(Item As Outlook.MailItem)
Item.Subject = MailItem.Subject & ("#@work")
Item.Save

Set myForward = Item.Forward
myForward.Recipients.Add "myemail@emailhost.com"

' To BCC an address or DL, try this:
'myForward.BCC = "alias"

myForward.DeleteAfterSubmit = True

myForward.Send

End Sub




but .. it doesn't work.. and the moving part is missing.. AND it changes the subject of the original email.. so pretty much not what I want..

Can someone finish the script?

My knowledge of VBA is just above what you see above.. And I copied that from a website.. then tried adding the "Item.Subject = MailItem.Subject & ("#@work")"

which didn't work at all.. without the mailitem.subject it renamed my original email to #@work :-|

thistle
08-01-2013, 07:20 AM
In that snippet, Item refers to the original item so changing the subject of Item and saving it will affect the original email.

I think all you need to do is rearrange the code so it works like you would do it if you were doing it manually i.e. Click Forward, then start changing the subject of the new message etc.


Sub ForwardEmail(Item As Outlook.MailItem)

Set myForward = Item.Forward

myforward.Subject = Item.Subject & ("#@work")
myForward.Recipients.Add "myemail@emailhost.com"

' To BCC an address or DL, try this:
'myForward.BCC = "alias"

myForward.DeleteAfterSubmit = True

myForward.Send

End Sub

I'm not sure exactly what you need to do with your macro, but can you accomplish what you need using rules only?
You can forward emails (which adds something to the subject or the header saying it has been auto forwarded) and move messages to folders.