Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-03-2015, 01:03 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 12-03-2015, 02:07 AM
gmayor's Avatar
gmayor gmayor is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 12-03-2015, 02:44 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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!)
Reply With Quote
  #4  
Old 12-03-2015, 04:33 AM
gmayor's Avatar
gmayor gmayor is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #5  
Old 12-03-2015, 04:51 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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
What happens is almost perfect - but the mail doesn't get sent. I end up with the message window open and waiting for me to click "send". I think that it would be perfect if I could have this whole thing run without my intervention at all. Any thoughts?
Reply With Quote
  #6  
Old 12-03-2015, 05:48 AM
gmayor's Avatar
gmayor gmayor is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #7  
Old 12-03-2015, 06:10 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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!
Reply With Quote
  #8  
Old 12-09-2015, 03:42 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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
And this is what the rule looks like:
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
Reply With Quote
  #9  
Old 12-09-2015, 05:14 AM
gmayor's Avatar
gmayor gmayor is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #10  
Old 12-09-2015, 05:21 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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?
Reply With Quote
  #11  
Old 12-09-2015, 05:32 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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.
Reply With Quote
  #12  
Old 12-24-2015, 07:29 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

*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
Reply With Quote
  #13  
Old 12-25-2015, 01:08 AM
gmayor's Avatar
gmayor gmayor is offline Auto-forward HTML emails with added suffix to subject line Windows 10 Auto-forward HTML emails with added suffix to subject line Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #14  
Old 12-25-2015, 01:54 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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
Reply With Quote
  #15  
Old 01-24-2016, 02:31 AM
paulkaye paulkaye is offline Auto-forward HTML emails with added suffix to subject line Windows 7 64bit Auto-forward HTML emails with added suffix to subject line Office 2007
Advanced Beginner
Auto-forward HTML emails with added suffix to subject line
 
Join Date: Nov 2011
Posts: 84
paulkaye is on a distinguished road
Default

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
Reply With Quote
Reply

Tags
autoforward, edit subject



Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto-forward HTML emails with added suffix to subject line 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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:31 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft