|
|
| Next: Side by Side Calendar View |
| Author |
Message |
mecg96 External

Since: Jul 26, 2005 Posts: 15
|
Posted: Wed Aug 10, 2005 6:59 am Post subject: Running a Macro when email arrives Archived from groups: microsoft>public>outlook>program_vba (more info?) |
|
|
|
| I want to run a macro when an email with a specific Subject arrives, how can
I check every email that comes in?
Thanks!!
|
|
|
| Back to top |
|
 |
Sue Mosher [MVP-Outlook] External

Since: Feb 11, 2005 Posts: 21627
|
Posted: Wed Aug 10, 2005 10:08 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
' do stuff with olMail, e.g.
MsgBox olMail.Subject
Set olMail = Nothing
Set olNS = Nothing
End Sub
See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"mecg96" <mecg96.RemoveThis@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
>I want to run a macro when an email with a specific Subject arrives, how can
> I check every email that comes in?
>
> Thanks!! |
|
| Back to top |
|
 |
mecg96 External

Since: Jul 26, 2005 Posts: 15
|
Posted: Wed Aug 10, 2005 10:08 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Thanks Sue,
another question: How will it execute each time a new email arrives?
"Sue Mosher [MVP-Outlook]" wrote:
> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
>
> Sub RunAScriptRuleRoutine(MyMail As MailItem)
> Dim strID As String
> Dim olNS As Outlook.NameSpace
> Dim olMail As Outlook.MailItem
>
> strID = MyMail.EntryID
> Set olNS = Application.GetNamespace("MAPI")
> Set olMail = olNS.GetItemFromID(strID)
> ' do stuff with olMail, e.g.
> MsgBox olMail.Subject
>
> Set olMail = Nothing
> Set olNS = Nothing
> End Sub
>
> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
>
> --
> Sue Mosher, Outlook MVP
> Author of
> Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "mecg96" <mecg96.DeleteThis@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
> >I want to run a macro when an email with a specific Subject arrives, how can
> > I check every email that comes in?
> >
> > Thanks!!
> |
|
| Back to top |
|
 |
Sue Mosher [MVP-Outlook] External

Since: Feb 11, 2005 Posts: 21627
|
Posted: Wed Aug 10, 2005 11:04 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Set whatever conditions you like in the rules wizard, no doubt a condition to check the subject for particular text, given what you described originally as your scenario.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"mecg96" <mecg96.RemoveThis@discussions.microsoft.com> wrote in message news:57AA7C3D-CB22-4FE3-982A-3F9BC8E57F65@microsoft.com...
> Thanks Sue,
>
> another question: How will it execute each time a new email arrives?
>
>
> "Sue Mosher [MVP-Outlook]" wrote:
>
>> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
>>
>> Sub RunAScriptRuleRoutine(MyMail As MailItem)
>> Dim strID As String
>> Dim olNS As Outlook.NameSpace
>> Dim olMail As Outlook.MailItem
>>
>> strID = MyMail.EntryID
>> Set olNS = Application.GetNamespace("MAPI")
>> Set olMail = olNS.GetItemFromID(strID)
>> ' do stuff with olMail, e.g.
>> MsgBox olMail.Subject
>>
>> Set olMail = Nothing
>> Set olNS = Nothing
>> End Sub
>>
>> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
>>
>> --
>> Sue Mosher, Outlook MVP
>> Author of
>> Microsoft Outlook Programming - Jumpstart for
>> Administrators, Power Users, and Developers
>> http://www.outlookcode.com/jumpstart.aspx
>>
>>
>> "mecg96" <mecg96.RemoveThis@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
>> >I want to run a macro when an email with a specific Subject arrives, how can
>> > I check every email that comes in?
>> >
>> > Thanks!!
>> |
|
| Back to top |
|
 |
mecg96 External

Since: Jul 26, 2005 Posts: 15
|
Posted: Wed Aug 10, 2005 11:04 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Thanks!! This was really helpful
"Sue Mosher [MVP-Outlook]" wrote:
> Set whatever conditions you like in the rules wizard, no doubt a condition to check the subject for particular text, given what you described originally as your scenario.
>
> --
> Sue Mosher, Outlook MVP
> Author of
> Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "mecg96" <mecg96.TakeThisOut@discussions.microsoft.com> wrote in message news:57AA7C3D-CB22-4FE3-982A-3F9BC8E57F65@microsoft.com...
> > Thanks Sue,
> >
> > another question: How will it execute each time a new email arrives?
> >
> >
> > "Sue Mosher [MVP-Outlook]" wrote:
> >
> >> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
> >>
> >> Sub RunAScriptRuleRoutine(MyMail As MailItem)
> >> Dim strID As String
> >> Dim olNS As Outlook.NameSpace
> >> Dim olMail As Outlook.MailItem
> >>
> >> strID = MyMail.EntryID
> >> Set olNS = Application.GetNamespace("MAPI")
> >> Set olMail = olNS.GetItemFromID(strID)
> >> ' do stuff with olMail, e.g.
> >> MsgBox olMail.Subject
> >>
> >> Set olMail = Nothing
> >> Set olNS = Nothing
> >> End Sub
> >>
> >> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
> >>
> >> --
> >> Sue Mosher, Outlook MVP
> >> Author of
> >> Microsoft Outlook Programming - Jumpstart for
> >> Administrators, Power Users, and Developers
> >> http://www.outlookcode.com/jumpstart.aspx
> >>
> >>
> >> "mecg96" <mecg96.TakeThisOut@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
> >> >I want to run a macro when an email with a specific Subject arrives, how can
> >> > I check every email that comes in?
> >> >
> >> > Thanks!!
> >>
> |
|
| Back to top |
|
 |
Giles External

Since: Aug 19, 2005 Posts: 5
|
Posted: Fri Aug 19, 2005 9:12 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Sue,
Can I step back a bit on to a more basic level?
I've got an Outlook macro which I've successfully operated via a toolbar
button to check that it works. Like mecg96, I want it to run when a rule is
processed. I've created the rule up to the point of specifying the action to
take.
However, when I select "run a script" here, I get a window entitled "Select
Script" with an empty box underneath; there's nothing to click on in the box
and the only options I have are two buttons: OK and Close.
How do I link my macro to the rule? Should I be putting my macro script
somewhere special rather than in the "ThisOutlookSession" procedure in VBA?
"Sue Mosher [MVP-Outlook]" wrote:
> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
>
> Sub RunAScriptRuleRoutine(MyMail As MailItem)
> Dim strID As String
> Dim olNS As Outlook.NameSpace
> Dim olMail As Outlook.MailItem
>
> strID = MyMail.EntryID
> Set olNS = Application.GetNamespace("MAPI")
> Set olMail = olNS.GetItemFromID(strID)
> ' do stuff with olMail, e.g.
> MsgBox olMail.Subject
>
> Set olMail = Nothing
> Set olNS = Nothing
> End Sub
>
> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
>
> --
> Sue Mosher, Outlook MVP
> Author of
> Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "mecg96" <mecg96.TakeThisOut@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
> >I want to run a macro when an email with a specific Subject arrives, how can
> > I check every email that comes in?
> >
> > Thanks!!
> |
|
| Back to top |
|
 |
Sue Mosher [MVP-Outlook] External

Since: Feb 11, 2005 Posts: 21627
|
Posted: Tue Aug 23, 2005 9:12 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Your "macro" needs to be in the format I described earlier -- a Public Sub with a single MailItem argument. In other words, the procedure structure is not the same as that for a macro that you can run from a toolbar button (which is a Public but argumentless Sub).
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"Giles" <Giles.DeleteThis@discussions.microsoft.com> wrote in message news:86D0B5EB-ABFF-4D59-AB07-3459BF17F86F@microsoft.com...
> Sue,
>
> Can I step back a bit on to a more basic level?
>
> I've got an Outlook macro which I've successfully operated via a toolbar
> button to check that it works. Like mecg96, I want it to run when a rule is
> processed. I've created the rule up to the point of specifying the action to
> take.
>
> However, when I select "run a script" here, I get a window entitled "Select
> Script" with an empty box underneath; there's nothing to click on in the box
> and the only options I have are two buttons: OK and Close.
>
> How do I link my macro to the rule? Should I be putting my macro script
> somewhere special rather than in the "ThisOutlookSession" procedure in VBA?
>
> "Sue Mosher [MVP-Outlook]" wrote:
>
>> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
>>
>> Sub RunAScriptRuleRoutine(MyMail As MailItem)
>> Dim strID As String
>> Dim olNS As Outlook.NameSpace
>> Dim olMail As Outlook.MailItem
>>
>> strID = MyMail.EntryID
>> Set olNS = Application.GetNamespace("MAPI")
>> Set olMail = olNS.GetItemFromID(strID)
>> ' do stuff with olMail, e.g.
>> MsgBox olMail.Subject
>>
>> Set olMail = Nothing
>> Set olNS = Nothing
>> End Sub
>>
>> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
>>
>> --
>> Sue Mosher, Outlook MVP
>> Author of
>> Microsoft Outlook Programming - Jumpstart for
>> Administrators, Power Users, and Developers
>> http://www.outlookcode.com/jumpstart.aspx
>>
>>
>> "mecg96" <mecg96.DeleteThis@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
>> >I want to run a macro when an email with a specific Subject arrives, how can
>> > I check every email that comes in?
>> >
>> > Thanks!!
>> |
|
| Back to top |
|
 |
Giles External

Since: Aug 19, 2005 Posts: 5
|
Posted: Mon Sep 05, 2005 7:47 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Sue,
Apologies for not responding sooner - I didn't get a notification (maybe our
spam filters are overzelous) and haven't had a chance to check the site until
today.
Thanks very much for your suggestion which, although a little daunting for a
self-taught novice, looks feasible. I'll give it a try, and if you hear
nothing more from me you may assume
a) that it worked, and
b) that I'm grateful!
Giles. |
|
| Back to top |
|
 |
BenL712 External

Since: Oct 07, 2005 Posts: 1
|
Posted: Fri Oct 07, 2005 8:15 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Is there any way to accomplish the same thing in Outlook 2000?
"Sue Mosher [MVP-Outlook]" wrote:
> Your "macro" needs to be in the format I described earlier -- a Public Sub with a single MailItem argument. In other words, the procedure structure is not the same as that for a macro that you can run from a toolbar button (which is a Public but argumentless Sub).
> --
> Sue Mosher, Outlook MVP
> Author of
> Microsoft Outlook Programming - Jumpstart for
> Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
> "Giles" <Giles.TakeThisOut@discussions.microsoft.com> wrote in message news:86D0B5EB-ABFF-4D59-AB07-3459BF17F86F@microsoft.com...
> > Sue,
> >
> > Can I step back a bit on to a more basic level?
> >
> > I've got an Outlook macro which I've successfully operated via a toolbar
> > button to check that it works. Like mecg96, I want it to run when a rule is
> > processed. I've created the rule up to the point of specifying the action to
> > take.
> >
> > However, when I select "run a script" here, I get a window entitled "Select
> > Script" with an empty box underneath; there's nothing to click on in the box
> > and the only options I have are two buttons: OK and Close.
> >
> > How do I link my macro to the rule? Should I be putting my macro script
> > somewhere special rather than in the "ThisOutlookSession" procedure in VBA?
> >
> > "Sue Mosher [MVP-Outlook]" wrote:
> >
> >> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
> >>
> >> Sub RunAScriptRuleRoutine(MyMail As MailItem)
> >> Dim strID As String
> >> Dim olNS As Outlook.NameSpace
> >> Dim olMail As Outlook.MailItem
> >>
> >> strID = MyMail.EntryID
> >> Set olNS = Application.GetNamespace("MAPI")
> >> Set olMail = olNS.GetItemFromID(strID)
> >> ' do stuff with olMail, e.g.
> >> MsgBox olMail.Subject
> >>
> >> Set olMail = Nothing
> >> Set olNS = Nothing
> >> End Sub
> >>
> >> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
> >>
> >> --
> >> Sue Mosher, Outlook MVP
> >> Author of
> >> Microsoft Outlook Programming - Jumpstart for
> >> Administrators, Power Users, and Developers
> >> http://www.outlookcode.com/jumpstart.aspx
> >>
> >>
> >> "mecg96" <mecg96.TakeThisOut@discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
> >> >I want to run a macro when an email with a specific Subject arrives, how can
> >> > I check every email that comes in?
> >> >
> >> > Thanks!!
> >>
> |
|
| Back to top |
|
 |
Sue Mosher [MVP-Outlook] External

Since: Feb 11, 2005 Posts: 21627
|
Posted: Fri Oct 07, 2005 1:27 pm Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
The pages at http://www.outlookcode.com/d/code/zaphtml.htm and http://www.outlookcode.com/d/code/quarexe.htm provide examples of routines that run whenever a new message hits the Inbox. That would be the preferred Outlook 2000 solution.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"BenL712" <BenL712 DeleteThis @discussions.microsoft.com> wrote in message news:8F354B69-97C6-463B-9764-901D37F87391@microsoft.com...
> Is there any way to accomplish the same thing in Outlook 2000?
>
> "Sue Mosher [MVP-Outlook]" wrote:
>
>> Your "macro" needs to be in the format I described earlier -- a Public Sub with a single MailItem argument. In other words, the procedure structure is not the same as that for a macro that you can run from a toolbar button (which is a Public but argumentless Sub).
>>
>> "Giles" <Giles DeleteThis @discussions.microsoft.com> wrote in message news:86D0B5EB-ABFF-4D59-AB07-3459BF17F86F@microsoft.com...
>> > Sue,
>> >
>> > Can I step back a bit on to a more basic level?
>> >
>> > I've got an Outlook macro which I've successfully operated via a toolbar
>> > button to check that it works. Like mecg96, I want it to run when a rule is
>> > processed. I've created the rule up to the point of specifying the action to
>> > take.
>> >
>> > However, when I select "run a script" here, I get a window entitled "Select
>> > Script" with an empty box underneath; there's nothing to click on in the box
>> > and the only options I have are two buttons: OK and Close.
>> >
>> > How do I link my macro to the rule? Should I be putting my macro script
>> > somewhere special rather than in the "ThisOutlookSession" procedure in VBA?
>> >
>> > "Sue Mosher [MVP-Outlook]" wrote:
>> >
>> >> A "run a script" rule action takes a MailItem or MeetingItem as its parameter, then uses that item in the code:
>> >>
>> >> Sub RunAScriptRuleRoutine(MyMail As MailItem)
>> >> Dim strID As String
>> >> Dim olNS As Outlook.NameSpace
>> >> Dim olMail As Outlook.MailItem
>> >>
>> >> strID = MyMail.EntryID
>> >> Set olNS = Application.GetNamespace("MAPI")
>> >> Set olMail = olNS.GetItemFromID(strID)
>> >> ' do stuff with olMail, e.g.
>> >> MsgBox olMail.Subject
>> >>
>> >> Set olMail = Nothing
>> >> Set olNS = Nothing
>> >> End Sub
>> >>
>> >> See http://www.outlookcode.com/d/code/zaphtml.htm#ol2002 for another example and alternative approaches.
>> >>
>> >> --
>> >> Sue Mosher, Outlook MVP
>> >> Author of
>> >> Microsoft Outlook Programming - Jumpstart for
>> >> Administrators, Power Users, and Developers
>> >> http://www.outlookcode.com/jumpstart.aspx
>> >>
>> >>
>> >> "mecg96" <mecg96 DeleteThis @discussions.microsoft.com> wrote in message news:602581A1-8EDC-4AF9-98B3-14424581AEA1@microsoft.com...
>> >> >I want to run a macro when an email with a specific Subject arrives, how can
>> >> > I check every email that comes in?
>> >> >
>> >> > Thanks!!
>> >>
>> |
|
| Back to top |
|
 |
Rob Girard External

Since: Jul 09, 2009 Posts: 1
|
Posted: Thu Jul 09, 2009 8:10 am Post subject: Re: Running a Macro when email arrives [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Hi Sue,
Your script is very useful and I have mange to create this to flash up with
a msg box when the email arrives with a specific subject.
Is there a way I can use this same code to open an Excel document?
Thanks
Rob
url:http://www.ureader.com/msg/1081942.aspx |
|
| Back to top |
|
 |
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|