Outlook - Need help creating a macro in Outlook

Asked By Rodney Squires on 16-Mar-12 03:59 PM
I need help creating a macro in outlook that will search new incoming emails for certain words in the subject and then forward that email removing the FW in the subject and removing the forward header information in the body of the email, and make it look like it was sent from that email address, instead of the one that it was originally sent from.  I found one that does what I need, here http://community.spiceworks.com/scripts/show/771-forward-e-mail-to-helpdesk-from-outlook but it only forwards the selected email. I will have this running on a system that isn't monitored, so I need it to actually select the email in outlook so that it will forward the appropriate information. The way this one is now, when an email comes along that the rule sees meets the criteria, it runs the script, but it doesn't send the information in the correct email, it sends out the body of text from the selected email, not the email that just arrived. 

Donald Ross replied to Rodney Squires on 16-Mar-12 10:17 PM

Using the link and the script offered I was able to change the "helpdesk email to my own for testing and create a new email, send it to my self.  then as you say select it, run the macro and get an exact copy of the email without the FW: and it looks like it was just sent to me (albeit from me) 

My question is what part is missing.   you say the body of the message and the correct message or email.  
If a message sent to me simply saying 'hello donald'. the script would send that same email right back to me without the FW: as it is coded right now.

Can you tell me how you sent up the rules in order for the code to run when the rules were met?


Danasegarane Arunachalam replied to Rodney Squires on 16-Mar-12 10:23 PM
You can create the rule Alert for this one

1. In the Rule Alert use the Redirect instead of forward option

So what is the difference of Redirect option vs forward option

Both do the same purpose. But in redirect option the FW in the subject mail will  be removed. And the sender name will remain the same.

Here are the steps

  • From the Tools menu choose the Rules and Alert
  • Click New Rule
  • From the Popup Choose from a blank rule
  • Select the option as "Mail when they arrive"
  • Click next to continue
  • And in step1 select the option as shown below. (Subject contains something)


  •       And from the option choose the Redirect to people option and mention the id


  •      Save the Rule
  • Now test the rule
  • I have use the Outlook 2003 for demo purpose

Rodney Squires replied to Donald Ross on 17-Mar-12 09:39 AM
I have a rule that runs the script only if certain words are in a new email subject and from only certain email accounts.  The rule runs, and the script runs, but Outlook does not send the correct msg.  When you are in front of your PC and select the newest email and run the script it works, but I will not be monitoring this PC so when a new email comes in, Outlook runs the script if the new email meets the criteria, but Outlook does not select that email, it sends the email below it (which is selected).  When you open Outlook, it automatically selects the email at the top of the list, when a new email comes in, it shows up right above the email that is selected, but Outlook does not select that new email unless you click on it. If you are not monitoring Outlook, the same email will stay selected all the time.

I not only need the rule and script to run, I need that email selected in Outlook. 
Donald Ross replied to Rodney Squires on 17-Mar-12 01:11 PM

I understand what you are saying.. (I think)
You have a rule in place that is screening incomming email for key words, that runs your script. 
The problem is the script has a rule/code to (Set objItem = GetCurrentItem()).  This sends the wrong message.  It selects the last inbound/selected item as you mentioned above. 

I have been searching for a way to define or select what message to send, but I am not that good with Code and I am not sure how to change it.   

You could have a rule to run first to move all your non-criteria meeting email to a new folder upon arrival.  then when a message came in that fit the 2nd rule to run your script it would be the only one in the inbox.

Of course you would have to create a third rule to run after the script to move the criteria met email to a new folder as well. 

your inbox would be empty all the time and your messages would be devided into two new folders those that were forwarded and those that were not. 

That is my attempt at a work around.  some one with a little VB knowledge could do it easier than that.


Rodney Squires replied to Danasegarane Arunachalam on 17-Mar-12 05:07 PM
You can not use the Redirect rule outside of an Enterprise/Exchange environment. This is not in on an Exchange server.
yüksel öztezel yuksel oztezel replied to Rodney Squires on 17-Mar-12 06:23 PM
end of post
Danasegarane Arunachalam replied to Rodney Squires on 17-Mar-12 09:36 PM
Why don't you handle theNewMailEx Event .

Example here

Rodney Squires replied to Danasegarane Arunachalam on 21-Mar-12 04:50 PM
sounds like that might work, but im not sure how to incorporate it into the script; that is what i was hoping to get help with.  I'm new to this.