2

I am looking for a Outlook (2003) script.

What I need: I want to forward all my emails from mailbox-A (from a PC) to mailbox-B (on my phone). The catch is: This rule should only run, when I send a 'request' to mailbox-A.

What I did: I've created two rules in Outlook 2003.

Rule1- This rule forwards all emails from mailbox-A to mailbox-B. This rule works, but it is not automated (only runs when I press the button 'run rules'). I only want to receive emails 'when I want to'.

Rule2- I've created a second rule in Outlook. This rule starts (itself) when mailbox-A receives an email with 'get_mail' as email subject.

My goal: I want rule2 to start a script. Obviously, this script should run rule1.

Result: All emails from mailbox-A are forwarded to mailbox-B.

Backgroud: My goal is to read my work emails on my phone, commuting between work and home. By sending an email from my phone to my PC (with email subject get_mail), my PC (mailbox-A) forwards all emails to my phone (mailbox-B).

Is this possible using VBA? And how should the code look like? I have no experience with scripting, but I'm good with PCs and software in general. So I should be able install it when somebody supplies to the code.

(p.s. It is not possible to simply install the pop/imap account on my phone)

0

Yes, it is possible to have one rule trigger another rule. Here is a VBA procedure for Outlook that should work:

Sub RunRuleToForwardEmail(MyMail As MailItem)

    Dim st As Outlook.Store
    Dim myRule As Outlook.Rule

    ' get default store (where rules live)
    Set st = Application.Session.DefaultStore
    ' get rule
    Set myRule = st.GetRules("change_this_to_whatever_the_the_name_of_rule1_is") 'change this line
    myRule.Execute

End Sub

Remember to change this text: change_this_to_whatever_the_the_name_of_rule1_is.

Once you save your Outlook VBA Project, edit the actions of rule2. You should then be able to choose the above script in the list of options.

  • Thanks for you prompt answer. THe name of the rule is actually 'rule1'. So I changed your bit of the code into 'Set myRule = st.GetRules("rule1")'. Is that correct? I was able to select the script as action in rule2. Unfortunately it did not work. Did I make a mistake? – user316237 Apr 17 '14 at 4:13
  • Hm, yes that's correct. I tried it myself and it worked (although my rule1 just categorised my mail, didn't forward it). Add this extra code at the beginning of the procedure: MsgBox "The RunRuleToForwardEmail VBA procedure is running". Put this on it's own line before the first Dim statement. Then try it. If the code is running properly, a message should appear in Outlook to alert you. If this message doesn't appear, then something must be wrong with the rule that is meant to trigger it. – Garrulinae Apr 17 '14 at 4:22
  • No success :-(. Code is as followed: [Link]Sub RunRuleToForwardEmail(MyMail As MailItem) MsgBox "The RunRuleToForwardEmail VBA procedure is running" Dim st As Outlook.Store Dim myRule As Outlook.Rule Dim rl As Outlook.Rule ' get default store (where rules live) Set st = Application.Session.DefaultStore ' get rule Set myRule = st.GetRules(rule1) myRule.Execute End Sub – user316237 Apr 17 '14 at 4:26
  • Aha - the text rule1 has to be surrounded by quote marks: "rule1". The message should still have appeared, did it? – Garrulinae Apr 17 '14 at 4:29
  • I added the quote marks, nothing changed. I did not see any message either. I added to rule1 'set flag color green'. And to rule2 'set flag color purple'. When the email with subject get_mails comes arrives, this email gets a purple flag. Any other way to create a 'check'? – user316237 Apr 17 '14 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.