#1
|
|||
|
|||
Auto-forward HTML emails with added suffix to subject line
Hi,
I receive emails from an external system, and would like to set up a rule that can automatically forward them to another email address but with an added suffix in the subject line. The emails I receive are in HTML format. I've spent a few hours trying to achieve this, and my best luck was by following this post, but the forwarded mails were a little messy (I think they were converted into plain text). I don't usually work with macros or VBA, so if you have a solution, I'd be very grateful if you could provide full instructions! Thanks in advance, Paul |
#2
|
||||
|
||||
The following script run from a rule will forward the message to a given address with the additional text you specify. I have included a macro to test it
Code:
Option Explicit Sub Test() Dim olMsg As MailItem On Error Resume Next Set olMsg = ActiveExplorer.Selection.Item(1) ForwardWithSubject olMsg lbl_Exit: Exit Sub End Sub Sub ForwardWithSubject(olItem As Outlook.MailItem) Dim olOutMail As Outlook.MailItem Const strAddr As String = "someone@somewhere.com" Const strSubject As String = " Additional subject text" Set olOutMail = olItem.Forward With olOutMail .Subject = .Subject & strSubject .To = strAddr .Display 'Change to .Send after testing End With lbl_Exit: Set olOutMail = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thanks, Graham. Could you explain what you mean by "I have included a macro to test it"?
(Also, I just noticed your full name - are you the gmayor who has a web page on MS Word's find/replace functions? If so, thank you - I've had that page bookmarked for years, and refer back to it frequently!) |
#4
|
||||
|
||||
The main macro 'ForwardWithSubject' is intended to be run as a script from an Outlook rule. The other macro 'Test' calls that macro to process a selected message in your inbox, so that you can establish it does what you require.
Yes I am the same G Mayor - http://www.gmayor.com/replace_using_wildcards.htm I contribute to several forums as well as providing a web resource for Word users.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
Hi Graham,
So then many of us owe you a big thank you for all of the help & resources you've provided! Regarding the script you provided, I can test it myself simply by sending myself an email with the criteria that will trigger the rule that runs the script. Therefore I haven't included the test code you provided. I also didn't include the words "Option Explicit" as I wasn't sure what they were. So, my code simply says (with the subject suffix and email address filled in): Code:
Sub ForwardWithSubject(olItem As Outlook.MailItem) Dim olOutMail As Outlook.MailItem Const strAddr As String = "someone@somewhere.com" Const strSubject As String = " Additional subject text" Set olOutMail = olItem.Forward With olOutMail .Subject = .Subject & strSubject .To = strAddr .Display 'Change to .Send after testing End With lbl_Exit: Set olOutMail = Nothing Exit Sub End Sub |
#6
|
||||
|
||||
Option Explicit should go at the top of the module. It forces you to declare your variables and is good practice.
The test macro saves you the bother of sending messages to test the code. Did you see the comment in the line beginning .Display ? Change .Display to .Send when you are happy with the result.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
I warned you that I was a novice! I didn't see the comment - I didn't even know you could have comments in the middle of a line!
It works perfectly - thank you! |
#8
|
|||
|
|||
I don't know what's happened, but unfortunately this seems to have stopped working! Here's the script as it currently appears:
Code:
Option Explicit Sub ForwardWithSubjectGmayor(olItem As Outlook.MailItem) Dim olOutMail As Outlook.MailItem Const strAddr As String = "[email address removed]" Const strSubject As String = " [added string removed]" Set olOutMail = olItem.Forward With olOutMail .Subject = .Subject & strSubject .To = strAddr .Send End With lbl_Exit: Set olOutMail = Nothing Exit Sub End Sub https://dl.dropboxusercontent.com/u/...utlookrule.png Any idea why it would have stopped working?! In case it's relevant, when I first checked, the rule description included "this machine only" (which I think appeared by itself), but I removed that in case that was the problem - but it didn't help. You advice would be much appreciated! Paul Last edited by paulkaye; 12-09-2015 at 03:46 AM. Reason: image didn't appear in original post |
#9
|
||||
|
||||
It still works for me
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#10
|
|||
|
|||
I suspect that the reason my picture of the rule wouldn't work is that my url was https (and that's my only option - using Dropbox).
Anyway, do you have any idea why the rule/script might have stopped working? Did I do anything to the script? Should I just rewrite the rule? |
#11
|
|||
|
|||
I've now rewritten the rule from scratch, searching for asdfghjkl in the subject line. And it's not working!
In case it's relevant, my rule doesn't say "and stop processing more rules", like yours does. |
#12
|
|||
|
|||
*nudge*
I'd be really grateful if you (or anyone) could help me work out why this stopped working! It was perfect while it worked! I think it stopped working the first time I restarted my PC. Paul |
#13
|
||||
|
||||
Outlook can be fussy about macro security and it seems probable that your system's macro settings may be blocking the code. One possibility is to use selfcert.exe (in the Outlook application folder) and use it to digitally sign the macro project (from the VBA editor - Tools > Digital Signature.)
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#14
|
|||
|
|||
Hi Graham,
I was just about to write to you to say it hadn't worked, but then started to look at other security settings. After having added the certificate, it seems I needed to restart Outlook (when I closed Outlook I was prompted to save the VBA project). When I restarted I got an alert about the electronic signature, and after I accepted it, it started to work again. Thank you again for being so generous with your time and knowledge! Paul |
#15
|
|||
|
|||
Hi again,
How can I add a CC address to the mails that are sent my this macro? Also, if I edit the macro, do I need to self-sign it again? Thanks, Paul |
Tags |
autoforward, edit subject |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Outlook 2013 Auto Forward / Auto Redirect emails not working | katm3 | Outlook | 4 | 08-07-2015 01:50 AM |
Need to forward subject alone of mails | abhikulsh | Outlook | 1 | 08-28-2013 10:47 AM |
Forward emails not opening, why? | alexb123 | Outlook | 0 | 10-19-2012 02:22 PM |
Auto Subject Line | hollwall | Outlook | 0 | 04-19-2012 08:49 AM |
Auto Forward Emails - Specific Time Periods Only | Dav | Outlook | 0 | 06-22-2011 12:03 PM |