PC Review


Reply
Thread Tools Rate Thread

Create a macro in Outlook to run a rule

 
 
DLGolfs
Guest
Posts: n/a
 
      3rd Mar 2010
I created a rule in Outlook 2007 for e-mails that have certain words in the
subject line, to be deleted. I have checked the rule and made it first but
it does not run. I have to run it manually but clicking tools, rules and
alerts, run rules, etc. This is pain to do. All my other rules run with no
problem, this is the only one that does not run.
So I thought I would make a macro on the toolbar and then just click on that
and not have to click on tools, rules, etc.
How do I do that?
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      3rd Mar 2010
Sub RunRuleMyRule()
Application.Session.DefaultStore.GetRules.Item("myRuleName).Execute
End Sub

Customize the toolbar where you want the macro button and select the macro
from the Macros collection in the customize dialog. It will be in the
Commands tab under the Macros group. Drag it to where you want it. While in
customize you can click your new button and change the name and other
settings.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DLGolfs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I created a rule in Outlook 2007 for e-mails that have certain words in the
> subject line, to be deleted. I have checked the rule and made it first
> but
> it does not run. I have to run it manually but clicking tools, rules and
> alerts, run rules, etc. This is pain to do. All my other rules run with
> no
> problem, this is the only one that does not run.
> So I thought I would make a macro on the toolbar and then just click on
> that
> and not have to click on tools, rules, etc.
> How do I do that?


 
Reply With Quote
 
 
 
 
DLGolfs
Guest
Posts: n/a
 
      4th Mar 2010
I was directed to this site, but I don't know anything about programming, I
apologize. I put the macro on the toolbar but it does not show any macros are
created. That is my point, I have to create a macro and then I can run it
from the toolbar, but don't know how to creat a macro in Outlook b/c there is
no avenue to do it.
I unfortunatley do not understand the "sub runrulemyrule()" stuff, I am sorry

Why does only this rule not run? all the others run and I set them up the
same way, it runs manually, but not automatically.

ty

"Ken Slovak - [MVP - Outlook]" wrote:

> Sub RunRuleMyRule()
> Application.Session.DefaultStore.GetRules.Item("myRuleName).Execute
> End Sub
>
> Customize the toolbar where you want the macro button and select the macro
> from the Macros collection in the customize dialog. It will be in the
> Commands tab under the Macros group. Drag it to where you want it. While in
> customize you can click your new button and change the name and other
> settings.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "DLGolfs" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I created a rule in Outlook 2007 for e-mails that have certain words in the
> > subject line, to be deleted. I have checked the rule and made it first
> > but
> > it does not run. I have to run it manually but clicking tools, rules and
> > alerts, run rules, etc. This is pain to do. All my other rules run with
> > no
> > problem, this is the only one that does not run.
> > So I thought I would make a macro on the toolbar and then just click on
> > that
> > and not have to click on tools, rules, etc.
> > How do I do that?

>
> .
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      5th Mar 2010
I have no idea why one or the other of your rules isn't running
automatically, that has nothing to do with Outlook programming. That you can
ask on one of the general Outlook groups.

That code I showed is the macro. You use Alt+F11 to open the Outlook VBA
project and open a code module there and put the code there, then it will
show up as a macro. You just need to change the code to use the actual name
of your rule rather than "myRuleName".

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DLGolfs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I was directed to this site, but I don't know anything about programming, I
> apologize. I put the macro on the toolbar but it does not show any macros
> are
> created. That is my point, I have to create a macro and then I can run it
> from the toolbar, but don't know how to creat a macro in Outlook b/c there
> is
> no avenue to do it.
> I unfortunatley do not understand the "sub runrulemyrule()" stuff, I am
> sorry
>
> Why does only this rule not run? all the others run and I set them up the
> same way, it runs manually, but not automatically.
>
> ty


 
Reply With Quote
 
DLGolfs
Guest
Posts: n/a
 
      5th Mar 2010
OK here is what I did, the rules name is Delete spam:
Sub RunRuleDeleteSpam()
Application.Session.DefaultStore.GetRules.Item "Delete Spam.Execute"
End Sub

When I try to run it I get a run time error, The operation failed. An
object cannot be found. There is a number too.
I have the rule set up as Delete spam

then I made some changes and here is the string:
Sub RunRuleDeleteSpam()
Application.Session.DefaultStore.GetRules.Item Delete Spam.Execute
End Sub

now I am getting a syntax error

I am trying, never did this in the past, please be patient

"Ken Slovak - [MVP - Outlook]" wrote:

> I have no idea why one or the other of your rules isn't running
> automatically, that has nothing to do with Outlook programming. That you can
> ask on one of the general Outlook groups.
>
> That code I showed is the macro. You use Alt+F11 to open the Outlook VBA
> project and open a code module there and put the code there, then it will
> show up as a macro. You just need to change the code to use the actual name
> of your rule rather than "myRuleName".
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "DLGolfs" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I was directed to this site, but I don't know anything about programming, I
> > apologize. I put the macro on the toolbar but it does not show any macros
> > are
> > created. That is my point, I have to create a macro and then I can run it
> > from the toolbar, but don't know how to creat a macro in Outlook b/c there
> > is
> > no avenue to do it.
> > I unfortunatley do not understand the "sub runrulemyrule()" stuff, I am
> > sorry
> >
> > Why does only this rule not run? all the others run and I set them up the
> > same way, it runs manually, but not automatically.
> >
> > ty

>
> .
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      5th Mar 2010
Sub RunRuleDeleteSpam()
Application.Session.DefaultStore.GetRules.Item("Delete Spam").Execute
End Sub


--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DLGolfs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> OK here is what I did, the rules name is Delete spam:
> Sub RunRuleDeleteSpam()
> Application.Session.DefaultStore.GetRules.Item "Delete Spam.Execute"
> End Sub
>
> When I try to run it I get a run time error, The operation failed. An
> object cannot be found. There is a number too.
> I have the rule set up as Delete spam
>
> then I made some changes and here is the string:
> Sub RunRuleDeleteSpam()
> Application.Session.DefaultStore.GetRules.Item Delete Spam.Execute
> End Sub
>
> now I am getting a syntax error
>
> I am trying, never did this in the past, please be patient


 
Reply With Quote
 
DLGolfs
Guest
Posts: n/a
 
      5th Mar 2010
ok, copy , pasted below into the editor module, run "macro" from VBA and
outlook and nothing happens, sorry

I put in in a module and a design module and neither work.

"Ken Slovak - [MVP - Outlook]" wrote:

> Sub RunRuleDeleteSpam()
> Application.Session.DefaultStore.GetRules.Item("Delete Spam").Execute
> End Sub
>
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "DLGolfs" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > OK here is what I did, the rules name is Delete spam:
> > Sub RunRuleDeleteSpam()
> > Application.Session.DefaultStore.GetRules.Item "Delete Spam.Execute"
> > End Sub
> >
> > When I try to run it I get a run time error, The operation failed. An
> > object cannot be found. There is a number too.
> > I have the rule set up as Delete spam
> >
> > then I made some changes and here is the string:
> > Sub RunRuleDeleteSpam()
> > Application.Session.DefaultStore.GetRules.Item Delete Spam.Execute
> > End Sub
> >
> > now I am getting a syntax error
> >
> > I am trying, never did this in the past, please be patient

>
> .
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      5th Mar 2010
The macro should be in a code module.

So what happens? Do you get any errors or what? It might be necessary to
expand that one-liner so you can see where things are failing. Let's try
that:

Sub RunRuleDeleteSpam()
Dim oNS As Outlook.NameSpace
Dim oStore As Outlook.Store
Dim colRules As Outlook.Rules
Dim oRule as Outlook.Rule

Set oNS = Application.GetNameSpace("MAPI")
Set oStore = oNS.DefaultStore
Set colRules = oStore.Rules
Set oRule = colRules.Item("Delete Spam")
oRule.Execute
End Sub

Put your cursor in that macro in the VBA project and press F5. See what
happens when the macro executes, if you get any errors or what.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DLGolfs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> ok, copy , pasted below into the editor module, run "macro" from VBA and
> outlook and nothing happens, sorry
>
> I put in in a module and a design module and neither work.


 
Reply With Quote
 
DLGolfs
Guest
Posts: n/a
 
      5th Mar 2010
There is no code module only class module and module, so I used module.

cut and pasted, then ran and got run time error 438, Object does not support
property or method,
then it higlights this line:
Set colRules = oStore.Rules

"Ken Slovak - [MVP - Outlook]" wrote:

> The macro should be in a code module.
>
> So what happens? Do you get any errors or what? It might be necessary to
> expand that one-liner so you can see where things are failing. Let's try
> that:
>
> Sub RunRuleDeleteSpam()
> Dim oNS As Outlook.NameSpace
> Dim oStore As Outlook.Store
> Dim colRules As Outlook.Rules
> Dim oRule as Outlook.Rule
>
> Set oNS = Application.GetNameSpace("MAPI")
> Set oStore = oNS.DefaultStore
> Set colRules = oStore.Rules
> Set oRule = colRules.Item("Delete Spam")
> oRule.Execute
> End Sub
>
> Put your cursor in that macro in the VBA project and press F5. See what
> happens when the macro executes, if you get any errors or what.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "DLGolfs" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > ok, copy , pasted below into the editor module, run "macro" from VBA and
> > outlook and nothing happens, sorry
> >
> > I put in in a module and a design module and neither work.

>
> .
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      8th Mar 2010
A module is a code module.

Sorry, that line should have been:

Set colRules = oStore.GetRules()

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"DLGolfs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> There is no code module only class module and module, so I used module.
>
> cut and pasted, then ran and got run time error 438, Object does not
> support
> property or method,
> then it higlights this line:
> Set colRules = oStore.Rules


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create macro to run a rule - Outlook 2003 JHV Microsoft Outlook VBA Programming 0 12th Jan 2012 10:32 PM
how to create an auto reply rule/macro that wont create a new mess squalltheonly Microsoft Outlook Discussion 4 15th Nov 2008 05:03 PM
Sent Mail Rule doesn't move sent file, unless I manually run rule =?Utf-8?B?Qm9iYnlC?= Microsoft Outlook Discussion 5 3rd Apr 2007 03:03 AM
Outlook 'create rule' should allow rule for no sender or subject =?Utf-8?B?R3JlZyBN?= Microsoft Outlook Discussion 2 29th Jul 2005 08:11 PM
how to create new rule not currently available in rule wizzard =?Utf-8?B?QnJlbnQgU2Fuc29t?= Microsoft Outlook Discussion 0 1st Jun 2005 02:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 PM.