Create a macro in Outlook to run a rule

Status
Not open for further replies.
D

DLGolfs

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?
 
K

Ken Slovak - [MVP - Outlook]

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.

"DLGolfs" <DLGolfs> wrote in message

news:0E78A1ED-658B-4638-B327-5FAB36EA48BF@microsoft.com...
> 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?
 
D

DLGolfs

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
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.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:0E78A1ED-658B-4638-B327-5FAB36EA48BF@microsoft.com...
> >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?


> .
>
 
K

Ken Slovak - [MVP - Outlook]

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".

"DLGolfs" <DLGolfs> wrote in message

news:7AD5F61F-3081-492A-8EC8-ECB7271A2917@microsoft.com...
> 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
 
D

DLGolfs

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 :)
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".

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:7AD5F61F-3081-492A-8EC8-ECB7271A2917@microsoft.com...
> >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


> .
>
 
K

Ken Slovak - [MVP - Outlook]

Sub RunRuleDeleteSpam()

Application.Session.DefaultStore.GetRules.Item("Delete Spam").Execute

End Sub

"DLGolfs" <DLGolfs> wrote in message

news:29693FD9-2F8D-4070-975B-27ACC94DB7D2@microsoft.com...
> 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 :)
 
D

DLGolfs

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.
wrote:


> Sub RunRuleDeleteSpam()
> Application.Session.DefaultStore.GetRules.Item("Delete Spam").Execute
> End Sub

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:29693FD9-2F8D-4070-975B-27ACC94DB7D2@microsoft.com...
> > 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 :)


> .
>
 
K

Ken Slovak - [MVP - Outlook]

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.

"DLGolfs" <DLGolfs> wrote in message

news:82B84BF2-6551-446D-BCBA-CF47FD13C9FC@microsoft.com...
> 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.
 
D

DLGolfs

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
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.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:82B84BF2-6551-446D-BCBA-CF47FD13C9FC@microsoft.com...
> > 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.


> .
>
 
K

Ken Slovak - [MVP - Outlook]

A module is a code module.

Sorry, that line should have been:

Set colRules = oStore.GetRules()

"DLGolfs" <DLGolfs> wrote in message

news:464331FF-4564-43CE-B45B-3DB22E99BCDF@microsoft.com...
> 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
 
D

DLGolfs

Just so I know that I am doing it correctly, through VB or Oulook, I chose

macro and run macro and click ok?

I did that and nothing happened :(
wrote:


> A module is a code module.

> Sorry, that line should have been:

> Set colRules = oStore.GetRules()

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:464331FF-4564-43CE-B45B-3DB22E99BCDF@microsoft.com...
> > 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


> .
>
 
D

DLGolfs

By the way, I made sure the changed was saved, closed OUtlook, then opened

it, enabled the macros and tried to run it.

I made sure I was in the file it is suppose to run the rule.

But nothing happened, no errors
wrote:


> A module is a code module.

> Sorry, that line should have been:

> Set colRules = oStore.GetRules()

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:464331FF-4564-43CE-B45B-3DB22E99BCDF@microsoft.com...
> > 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


> .
>
 
K

Ken Slovak - [MVP - Outlook]

You will need to set a breakpoint, step the code and see what's going on

with it. To do so click in your macro code on the Set colRules line in the

left hand border of the code module window. The line should then be

highlighted. When you run the macro it will stop on that line.

You can then step the code from there using F8. At each step you can use the

Immediate and Locals windows (View, Immediate Window and Locals Window) to

check the values of various variables and to output information. Then you

can see what's going on.

"DLGolfs" <DLGolfs> wrote in message

news:61C3DB64-BFF4-4431-9528-6C391E8BF719@microsoft.com...
> By the way, I made sure the changed was saved, closed OUtlook, then opened
> it, enabled the macros and tried to run it.
> I made sure I was in the file it is suppose to run the rule.

> But nothing happened, no errors
 
D

DLGolfs

ok, i tried to "set a break point" to "run to cursor" on several lines but

then when I do that , I try to run the macro, it still does nothing, I hit

continue and it goes through the lines and still nothing happens

I am sorry that I can't do this for you. I have built computers and run a

lot of applicaitons but have never programmed and I appreciate your patience.
wrote:


> You will need to set a breakpoint, step the code and see what's going on
> with it. To do so click in your macro code on the Set colRules line in the
> left hand border of the code module window. The line should then be
> highlighted. When you run the macro it will stop on that line.

> You can then step the code from there using F8. At each step you can use the
> Immediate and Locals windows (View, Immediate Window and Locals Window) to
> check the values of various variables and to output information. Then you
> can see what's going on.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:61C3DB64-BFF4-4431-9528-6C391E8BF719@microsoft.com...
> > By the way, I made sure the changed was saved, closed OUtlook, then opened
> > it, enabled the macros and tried to run it.
> > I made sure I was in the file it is suppose to run the rule.
> > But nothing happened, no errors


> .
>
 
D

DLGolfs

It also said that it can't execute in breakmode
wrote:


> You will need to set a breakpoint, step the code and see what's going on
> with it. To do so click in your macro code on the Set colRules line in the
> left hand border of the code module window. The line should then be
> highlighted. When you run the macro it will stop on that line.

> You can then step the code from there using F8. At each step you can use the
> Immediate and Locals windows (View, Immediate Window and Locals Window) to
> check the values of various variables and to output information. Then you
> can see what's going on.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:61C3DB64-BFF4-4431-9528-6C391E8BF719@microsoft.com...
> > By the way, I made sure the changed was saved, closed OUtlook, then opened
> > it, enabled the macros and tried to run it.
> > I made sure I was in the file it is suppose to run the rule.
> > But nothing happened, no errors


> .
>
 
D

DLGolfs

I was thinking and I see whatyou are trying to see, but if I put a breakpoint

and nothing happens then I don't see what that shows.

If it goes through 6 lines, let's say then how do we see if it works if all

the lines are not run ?

sorry, just thoughts
wrote:


> You will need to set a breakpoint, step the code and see what's going on
> with it. To do so click in your macro code on the Set colRules line in the
> left hand border of the code module window. The line should then be
> highlighted. When you run the macro it will stop on that line.

> You can then step the code from there using F8. At each step you can use the
> Immediate and Locals windows (View, Immediate Window and Locals Window) to
> check the values of various variables and to output information. Then you
> can see what's going on.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:61C3DB64-BFF4-4431-9528-6C391E8BF719@microsoft.com...
> > By the way, I made sure the changed was saved, closed OUtlook, then opened
> > it, enabled the macros and tried to run it.
> > I made sure I was in the file it is suppose to run the rule.
> > But nothing happened, no errors


> .
>
 
K

Ken Slovak - [MVP - Outlook]

The idea is to see if the code runs without any errors, what the values of

the variables is at each step (for example Nothing for a Rules collection

tells us something, as does Nothing for the value of a Rule when you try to

get it), and what exactly is happening when each code line executes.

None of us can test or debug the code on your machine for you, obviously.

"DLGolfs" <DLGolfs> wrote in message

news:CBD2D030-400A-45B2-BEBB-C3CE49A5B74D@microsoft.com...
> I was thinking and I see whatyou are trying to see, but if I put a
> breakpoint
> and nothing happens then I don't see what that shows.

> If it goes through 6 lines, let's say then how do we see if it works if
> all
> the lines are not run ?
> sorry, just thoughts
 
D

DLGolfs

Sorry that I cannot do the programming that you want; but it does run without

errors, it is just that the "rule" does not run, when I mean "nothing" I mean

that the rulle does not run, it does not delete the spam in the junk folder.

No boxes open, nothing happens, like I did nothing.

I guess it just can't be done with a macro, thatnks for trying anyway, I'll

just have to do it manually, which is a real pain, but so be it.
wrote:


> The idea is to see if the code runs without any errors, what the values of
> the variables is at each step (for example Nothing for a Rules collection
> tells us something, as does Nothing for the value of a Rule when you try to
> get it), and what exactly is happening when each code line executes.

> None of us can test or debug the code on your machine for you, obviously.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:CBD2D030-400A-45B2-BEBB-C3CE49A5B74D@microsoft.com...
> >I was thinking and I see whatyou are trying to see, but if I put a
> >breakpoint
> > and nothing happens then I don't see what that shows.
> > If it goes through 6 lines, let's say then how do we see if it works if
> > all
> > the lines are not run ?
> > sorry, just thoughts


> .
>
 
D

DLGolfs

What are values of the vairables? Is there a way to see that?

All I know is if I run it and/or brekapoint it , then it either does

nothing, that is litterally nothing happens OR it opens VB and shows me the

first line in yellow
wrote:


> The idea is to see if the code runs without any errors, what the values of
> the variables is at each step (for example Nothing for a Rules collection
> tells us something, as does Nothing for the value of a Rule when you try to
> get it), and what exactly is happening when each code line executes.

> None of us can test or debug the code on your machine for you, obviously.

> >

>

> "DLGolfs" <DLGolfs> wrote in message
> news:CBD2D030-400A-45B2-BEBB-C3CE49A5B74D@microsoft.com...
> >I was thinking and I see whatyou are trying to see, but if I put a
> >breakpoint
> > and nothing happens then I don't see what that shows.
> > If it goes through 6 lines, let's say then how do we see if it works if
> > all
> > the lines are not run ?
> > sorry, just thoughts


> .
>
 
K

Ken Slovak - [MVP - Outlook]

Open the Locals window, that will show all variables in scope and their

values. I mentioned that earlier in the thread.

"DLGolfs" <DLGolfs> wrote in message

news:93771F75-56FC-4B23-9CF4-4F42C00E95A0@microsoft.com...
> What are values of the vairables? Is there a way to see that?

> All I know is if I run it and/or brekapoint it , then it either does
> nothing, that is litterally nothing happens OR it opens VB and shows me
> the
> first line in yellow
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
C Outlook VBA - Create Macro Move Contact field Item to Another Using Outlook 1
N How Can I create an Outlook Macro to import calendar? Outlook VBA and Custom Forms 1
S How to create a macro to insert a signature in Outlook 2007 Outlook VBA and Custom Forms 1
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
A Create Macro for hyperlink(email) in message body Outlook VBA and Custom Forms 9
L Macro Create Contact and Save Using Outlook 2
L Macro Create Contact and Save Using Outlook 8
S Macro to create notification emails Using Outlook 1
N Macro to create task Using Outlook 1
S Macro to create a new folder with subject line as the folder name Using Outlook 2
P Please Help me Create a Macro ! Using Outlook 2
S Macro to create a new contact, 2 appointments, and a task Using Outlook 1
M How to Create Macro in Visual Basic to add Contacts from Personal Folder Using Outlook 4
R How do I create a macro to put text in certain emails? Outlook VBA and Custom Forms 1
P How do I create a macro to add contacts from email messages? Outlook VBA and Custom Forms 1
J Macro to create folder in PST file Outlook VBA and Custom Forms 4
G Macro: Create New Message and Auto populate To Field Outlook VBA and Custom Forms 5
Chiba Create an appointment for all the members Outlook VBA and Custom Forms 1
S Create a clickable custom column field Outlook VBA and Custom Forms 0
O Create a custom contact form - questions before messing things up... Outlook VBA and Custom Forms 4
C Can't create Outlook data file Outlook Wishlist 0
L automaticaly create a teams meeting with a sync Using Outlook 0
D Can Exchange Admin Center create a pst for users email/contacts/calendar? Exchange Server Administration 0
S Create A Search Folder That Looks For Message Class? Outlook VBA and Custom Forms 0
F How to create phone number as links in notes of Contacts Using Outlook 2
Nessa Can't create new appointment Using Outlook 1
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
C Create new Message with shared contacts & BCC'ing recipients Outlook VBA and Custom Forms 0
O Multiple email accounts - hesitate to create a new profile Using Outlook 3
G Can't create Folder Groups in Outlook 2013 Using Outlook 0
N Outlook rules don't create a copy for bcc'ed emails Using Outlook 3
F Delete/create/reset Exchange mailbox on Outlook.com Using Outlook.com accounts in Outlook 3
R Can not create folder to store specific emails in in Outlook for Mac Using Outlook 1
W Create Search Folder excluding Specific Email Addresses Using Outlook 5
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
JackBlack What tools do you use to create the signature for email? Using Outlook 3
Rupert Dragwater How to create a new email with @outlook.com Using Outlook.com accounts in Outlook 32
F Should a new email account also create new contacts Using Outlook 2
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
R Outlook add-in to create new contact from an email. Using Outlook 0
Q Script to create a pst file for Archiving Using Outlook 1
Jennifer Murphy Can I create a Rule with Or'd conditions? Using Outlook 1
D Outlook macros to create meeting on shared calendar Outlook VBA and Custom Forms 10
G How do I create a custom pick list in VB for an outlook automated email? Outlook VBA and Custom Forms 1
L Create Custom Form Using Outlook 0
Diane Poremsky Create a Task when a Message is Flagged New Slipstick.com Articles 0
Stilgar Relsik Create a rule to copy text from an email and paste it in the subject line. Using Outlook 1
Diane Poremsky Create a custom field for Outlook messages New Slipstick.com Articles 0
Similar threads


















































Top