Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Create a macro in Outlook to run a rule (http://www.outlookbanter.com/outlook-vba/100634-create-macro-outlook-run-rule.html)

DLGolfs March 3rd 10 03:55 PM

Create a macro in Outlook to run a rule
 
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?

Ken Slovak - [MVP - Outlook] March 3rd 10 04:25 PM

Create a macro in Outlook to run a rule
 
Sub RunRuleMyRule()
Application.Session.DefaultStore.GetRules.Item("my RuleName).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" wrote in message
...
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?



DLGolfs March 4th 10 10:57 PM

Create a macro in Outlook to run a rule
 
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("my RuleName).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" wrote in message
...
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?


.


Ken Slovak - [MVP - Outlook] March 5th 10 02:02 PM

Create a macro in Outlook to run a rule
 
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" wrote in message
...
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



DLGolfs March 5th 10 05:05 PM

Create a macro in Outlook to run a rule
 
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" wrote in message
...
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] March 5th 10 05:48 PM

Create a macro in Outlook to run a rule
 
Sub RunRuleDeleteSpam()
Application.Session.DefaultStore.GetRules.Item("De lete 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" wrote in message
...
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 :)



DLGolfs March 5th 10 07:32 PM

Create a macro in Outlook to run a rule
 
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("De lete 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" wrote in message
...
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] March 5th 10 07:57 PM

Create a macro in Outlook to run a rule
 
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" wrote in message
...
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.



DLGolfs March 5th 10 09:54 PM

Create a macro in Outlook to run a rule
 
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" wrote in message
...
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] March 8th 10 01:27 PM

Create a macro in Outlook to run a rule
 
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" wrote in message
...
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



DLGolfs March 9th 10 12:22 AM

Create a macro in Outlook to run a rule
 
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 :(

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

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" wrote in message
...
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


.


DLGolfs March 9th 10 01:14 AM

Create a macro in Outlook to run a rule
 
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

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

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" wrote in message
...
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] March 9th 10 02:27 PM

Create a macro in Outlook to run a rule
 
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.

--
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" wrote in message
...
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



DLGolfs March 10th 10 12:58 AM

Create a macro in Outlook to run a rule
 
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.



"Ken Slovak - [MVP - Outlook]" 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.

--
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" wrote in message
...
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


.


DLGolfs March 10th 10 12:59 AM

Create a macro in Outlook to run a rule
 
It also said that it can't execute in breakmode

"Ken Slovak - [MVP - Outlook]" 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.

--
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" wrote in message
...
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


.


DLGolfs March 10th 10 01:23 AM

Create a macro in Outlook to run a rule
 
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

"Ken Slovak - [MVP - Outlook]" 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.

--
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" wrote in message
...
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


.


Ken Slovak - [MVP - Outlook] March 10th 10 02:26 PM

Create a macro in Outlook to run a rule
 
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.

--
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" wrote in message
...
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



DLGolfs March 10th 10 10:22 PM

Create a macro in Outlook to run a rule
 
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.

"Ken Slovak - [MVP - Outlook]" 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.

--
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" wrote in message
...
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


.


DLGolfs March 10th 10 11:39 PM

Create a macro in Outlook to run a rule
 
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

"Ken Slovak - [MVP - Outlook]" 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.

--
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" wrote in message
...
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


.


Ken Slovak - [MVP - Outlook] March 11th 10 03:13 PM

Create a macro in Outlook to run a rule
 
Open the Locals window, that will show all variables in scope and their
values. I mentioned that earlier in the thread.

--
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" wrote in message
...
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



Ken Slovak - [MVP - Outlook] March 11th 10 03:14 PM

Create a macro in Outlook to run a rule
 
It's not a matter of what programming I want, it's if you want your code to
work you have to debug it. All programming requires that. No one can do it
for you. I think it could work, but things need debugging.

--
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" wrote in message
...
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.



DLGolfs March 11th 10 08:47 PM

Create a macro in Outlook to run a rule
 
I am sorry, I did not mean that you should debug it; I just don't know what I
am doing. I went to 'help" and found out what the 'locals window" is. b/c I
did not kow what it was.
I thought that I could copy /paste the result in this e-mail but I do not
see an avenue to do that.

So, I ran it w/o breaks and it just shows this but, this is probably not
helpful:

ONs nothing Name space
Ostore nothing store
colrules nothing rules
orule nothing rule

then when I put a breakpoint at the end of the set colrules o store linee,
it gives me a ton of lines, what should I look for? Most have "+" signs and
I able to expand it

At least I understand now what you want me to do.

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

Open the Locals window, that will show all variables in scope and their
values. I mentioned that earlier in the thread.

--
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" wrote in message
...
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


.


Ken Slovak - [MVP - Outlook] March 12th 10 02:33 PM

Create a macro in Outlook to run a rule
 
If you looked at locals when the code had finished they would all be Nothing
(null). What you want to do is to put the breakpoint on the line after
colRules is set.

You should then see valid objects for NameSpace, Store and Rules objects.
For example instead of Nothing you'd be able to expand the value and see
settings such as Name.

That tells you the base objects you need are all set. Then using F8 to step
the code one executable line at a time you can execute that line of code and
see what other variables are doing. Does the rule you want get found and
instantiated as oRule, etc.

--
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" wrote in message
...
I am sorry, I did not mean that you should debug it; I just don't know what
I
am doing. I went to 'help" and found out what the 'locals window" is. b/c
I
did not kow what it was.
I thought that I could copy /paste the result in this e-mail but I do not
see an avenue to do that.

So, I ran it w/o breaks and it just shows this but, this is probably not
helpful:

ONs nothing Name space
Ostore nothing store
colrules nothing rules
orule nothing rule

then when I put a breakpoint at the end of the set colrules o store linee,
it gives me a ton of lines, what should I look for? Most have "+" signs
and
I able to expand it

At least I understand now what you want me to do.



DLGolfs March 12th 10 03:59 PM

Create a macro in Outlook to run a rule
 
OK, I put my cursor at the end of the line
Set colRules = oStore.GetRules()
right click, toggle , breakpoint, it turns brown,
click run and it shows

+module4 module4/module4
no variables
+ : oNS : : NameSpace/NameSpace
+ : oStore : : Store/Store
: colRules : Nothing : Rules
: oRule : Nothing : Rule

So I don't see Namespace, store and rules, I see what is above.

Now what? I cannot expand colRules or oRule there is no + sign

orules nothing

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

If you looked at locals when the code had finished they would all be Nothing
(null). What you want to do is to put the breakpoint on the line after
colRules is set.

You should then see valid objects for NameSpace, Store and Rules objects.
For example instead of Nothing you'd be able to expand the value and see
settings such as Name.

That tells you the base objects you need are all set. Then using F8 to step
the code one executable line at a time you can execute that line of code and
see what other variables are doing. Does the rule you want get found and
instantiated as oRule, etc.

--
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" wrote in message
...
I am sorry, I did not mean that you should debug it; I just don't know what
I
am doing. I went to 'help" and found out what the 'locals window" is. b/c
I
did not kow what it was.
I thought that I could copy /paste the result in this e-mail but I do not
see an avenue to do that.

So, I ran it w/o breaks and it just shows this but, this is probably not
helpful:

ONs nothing Name space
Ostore nothing store
colrules nothing rules
orule nothing rule

then when I put a breakpoint at the end of the set colrules o store linee,
it gives me a ton of lines, what should I look for? Most have "+" signs
and
I able to expand it

At least I understand now what you want me to do.


.


Ken Slovak - [MVP - Outlook] March 12th 10 04:18 PM

Create a macro in Outlook to run a rule
 
So what happens if you press F8 after you hit the breakpoint? You should be
in the line after setting colRules and colRules should not be Nothing and
should now have a + that you can expand to see properties such as Count,
which should have a number. Another F8 should instantiate your oRule object
and that then should not be Nothing and should be expandable to show
properties such as Name.

--
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" wrote in message
...
OK, I put my cursor at the end of the line
Set colRules = oStore.GetRules()
right click, toggle , breakpoint, it turns brown,
click run and it shows

+module4 module4/module4
no variables
+ : oNS : : NameSpace/NameSpace
+ : oStore : : Store/Store
: colRules : Nothing : Rules
: oRule : Nothing : Rule

So I don't see Namespace, store and rules, I see what is above.

Now what? I cannot expand colRules or oRule there is no + sign

orules nothing



DLGolfs March 12th 10 06:11 PM

Create a macro in Outlook to run a rule
 


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

So what happens if you press F8 after you hit the breakpoint? You should be
in the line after setting colRules and colRules should not be Nothing and
should now have a + that you can expand to see properties such as Count, THERE IS NO "PROPERTIES" AND NO "COUNT"


I GET THE FOLLOWING AND WHEN i EXPAND THE ONS THERE IS NO 'COUNT" JUST
ACCOUNTS, ADDRESS LISTS, APPLICATIONS, CATERGORIES, CURRENT USER, DEFAULT
STORE, FOLDERS MAPIOBJECT, PARENT SESSION, STORES, AND SYNCOBJECTS ...DO YOU
MEAN ACCOUNT OR COUNT? THIS IS WHAT I SEE EVERYTIME, :
- : Module4 : : Module4/Module4
: oStore : Nothing : Store
: oNS : Nothing : NameSpace
: colRules : Nothing : Rules
: oRule : Nothing : Rule
OK, THEN F8 AND IT HIGHLIGHTS THE FIRST LINE AND NOTHING CHANGES AS YOU SEE
ABOVE
THEN ANOTHER F8 AND IT HIGHLIGHTS THE SET ONS LINE AND NOTHING CHANGES AS
YOU SEE ABOVE
THEN ANOTHER F8 AND IT HIGHLIGHTS THE SET OSTORE LINE AND AGAIN NOTHING
CHANGES AS YOU SEE ABOVE AND SO ON
IF SOMETHING IS CHANGING IN THE EXPANSION, IT WOULD IMPOSSIBLE FOR ME TO
TELL UNLESS YOU DIRECT ME TO A CERTAIN PLACE


which should have a number WHERE?

.. Another F8 should instantiate your oRule object
and that then should not be Nothing and should be expandable to show
properties such as Name.

--
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" wrote in message
...
OK, I put my cursor at the end of the line
Set colRules = oStore.GetRules()
right click, toggle , breakpoint, it turns brown,
click run and it shows

+module4 module4/module4
no variables
+ : oNS : : NameSpace/NameSpace
+ : oStore : : Store/Store
: colRules : Nothing : Rules
: oRule : Nothing : Rule

So I don't see Namespace, store and rules, I see what is above.

Now what? I cannot expand colRules or oRule there is no + sign

orules nothing


.


Ken Slovak - [MVP - Outlook] March 15th 10 12:52 PM

Create a macro in Outlook to run a rule
 
In case you didn't know it all caps is hard to read and is considered as
shouting.

I have no idea what's going on. If you never get valid NameSpace, Store or
Rules collection objects obviously the code will never fire the rule. But
the code to get those objects should just work.

You are running this in Outlook 2007, with nothing in the code other than
what's been shown, and no errors are fired?

Select Tools, Trust Center and select the Macro Security tab. What is the
setting there? What about on the Programmatic Access tab?

Something is drastically wrong with your setup or there's something going on
that we're not being told about. Otherwise at minimum the line setting
NameSpace would work.

--
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" wrote in message
...


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

So what happens if you press F8 after you hit the breakpoint? You should
be
in the line after setting colRules and colRules should not be Nothing and
should now have a + that you can expand to see properties such as Count,
THERE IS NO "PROPERTIES" AND NO "COUNT"


I GET THE FOLLOWING AND WHEN i EXPAND THE ONS THERE IS NO 'COUNT" JUST
ACCOUNTS, ADDRESS LISTS, APPLICATIONS, CATERGORIES, CURRENT USER, DEFAULT
STORE, FOLDERS MAPIOBJECT, PARENT SESSION, STORES, AND SYNCOBJECTS ...DO
YOU
MEAN ACCOUNT OR COUNT? THIS IS WHAT I SEE EVERYTIME, :
- : Module4 : : Module4/Module4
: oStore : Nothing : Store
: oNS : Nothing : NameSpace
: colRules : Nothing : Rules
: oRule : Nothing : Rule
OK, THEN F8 AND IT HIGHLIGHTS THE FIRST LINE AND NOTHING CHANGES AS YOU
SEE
ABOVE
THEN ANOTHER F8 AND IT HIGHLIGHTS THE SET ONS LINE AND NOTHING CHANGES AS
YOU SEE ABOVE
THEN ANOTHER F8 AND IT HIGHLIGHTS THE SET OSTORE LINE AND AGAIN NOTHING
CHANGES AS YOU SEE ABOVE AND SO ON
IF SOMETHING IS CHANGING IN THE EXPANSION, IT WOULD IMPOSSIBLE FOR ME TO
TELL UNLESS YOU DIRECT ME TO A CERTAIN PLACE



DLGolfs March 22nd 10 10:13 PM

Create a macro in Outlook to run a rule
 
Well , I answered you some time ago so I guess you have given up on me.
Sorry I don't know how to program, I put what you wrote and it did not work.
I really thought that is what the disussion groups are for, to help people
like me who know nothing about programming. I guess I'll have to try someone
else to give me the answer.

If you were offended by the CAPS, then I don't kow what to say about that!
WHy would I do someone to offend someone who is helping me? Truth is, i
wouldn't.
Oh well so be it.



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

Open the Locals window, that will show all variables in scope and their
values. I mentioned that earlier in the thread.

--
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" wrote in message
...
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


.


Ken Slovak - [MVP - Outlook] March 23rd 10 01:20 PM

Create a macro in Outlook to run a rule
 
I had answered each one of your posts. Then you started a new thread and I
figured you decided to try to get answers from someone else. So I left that
thread alone.

I'm certainly willing to continue to try to help, but I'm really at a loss.
As I said in my last post, other than the information about caps, which did
not offend me:

I have no idea what's going on. If you never get valid NameSpace, Store or
Rules collection objects obviously the code will never fire the rule. But
the code to get those objects should just work.

You are running this in Outlook 2007, with nothing in the code other than
what's been shown, and no errors are fired?

Select Tools, Trust Center and select the Macro Security tab. What is the
setting there? What about on the Programmatic Access tab?

Something is drastically wrong with your setup or there's something going on
that we're not being told about. Otherwise at minimum the line setting
NameSpace would work.

The first thing, before any rules stuff, is that you should be getting a
valid NameSpace object. If you aren't then something is drastically wrong
that must be corrected before any of your code will run at all. I'd be
curious about the security settings as I asked, and I'd also be curious to
see if you are running an anti-virus program that maybe is breaking code
with a script stopper.

--
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" wrote in message
...
Well , I answered you some time ago so I guess you have given up on me.
Sorry I don't know how to program, I put what you wrote and it did not
work.
I really thought that is what the disussion groups are for, to help people
like me who know nothing about programming. I guess I'll have to try
someone
else to give me the answer.

If you were offended by the CAPS, then I don't kow what to say about that!
WHy would I do someone to offend someone who is helping me? Truth is, i
wouldn't.
Oh well so be it.



DLGolfs March 28th 10 02:24 PM

Create a macro in Outlook to run a rule
 
Ken:
First, I went to someone else b/c I left my reply on 3/16 and had not heard
anyting and gave up on 3/22, that is why I tried someone else.

Secondly, I gave you all these security settings already in an earlier post.
from 3/16 but here it is again: So I'll do it this way:
Yes, OUtlook 2007, no errors, when I run the macro through OUtlook, it opens
VB and highlights the Setcol Rules line, that is it, not errors

Programming says "warn me about suspicious.....(recommended)"

Warnings for all macros
Warn me about suspecious activity when my , etc etc
Bottom line, is that you wrote the program, not me, and I used a lot of time
to figure out what you were asking and tried to answer the best of my
ability. I gave up b/c I had not heard from you in 6 days, hey maybe you
were on vacation, but I just figured you got ****ed off and was frustrated
that I was SO dumb about this.

My rule runs fine manually, it is call Delete Spam, I copied and pasted your
programming into VBA, enabled macros. Opened the junk folder, clicked on
macros, run the delete spam macro and all it does is highlight my first
e-mail in the junk folder, no errors nothing.

So maybe delete everything and start over. I have not gotten a response
from my other posts, just ignored me, oh well, so be it.
So whatever you want to do is fine with me.


You wrote:

The first thing, before any rules stuff, is that you should be getting a
valid NameSpace object. I If you aren't then something is drastically wrong
that must be corrected before any of your code will run at all. I'd be
curious about the security settings as I asked, and I'd also be curious to
see if you are running an anti-virus program that maybe is breaking code
with a script stopper.
I don't know what a valid NameSpace object looks like
I do run an anti-virus program called Avira, I can look to see if it is
stopping scripts but doubt it b/c I would have other indications of this,
don't you think?
Sorry about all this, but I just thought that you had given up on me!
"Ken Slovak - [MVP - Outlook]" wrote:

I had answered each one of your posts. Then you started a new thread and I
figured you decided to try to get answers from someone else. So I left that
thread alone.

I'm certainly willing to continue to try to help, but I'm really at a loss.
As I said in my last post, other than the information about caps, which did
not offend me:

I have no idea what's going on. If you never get valid NameSpace, Store or
Rules collection objects obviously the code will never fire the rule. But
the code to get those objects should just work.

You are running this in Outlook 2007, with nothing in the code other than
what's been shown, and no errors are fired?

Select Tools, Trust Center and select the Macro Security tab. What is the
setting there? What about on the Programmatic Access tab?

Something is drastically wrong with your setup or there's something going on
that we're not being told about. Otherwise at minimum the line setting
NameSpace would work.

The first thing, before any rules stuff, is that you should be getting a
valid NameSpace object. If you aren't then something is drastically wrong
that must be corrected before any of your code will run at all. I'd be
curious about the security settings as I asked, and I'd also be curious to
see if you are running an anti-virus program that maybe is breaking code
with a script stopper.

--
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" wrote in message
...
Well , I answered you some time ago so I guess you have given up on me.
Sorry I don't know how to program, I put what you wrote and it did not
work.
I really thought that is what the disussion groups are for, to help people
like me who know nothing about programming. I guess I'll have to try
someone
else to give me the answer.

If you were offended by the CAPS, then I don't kow what to say about that!
WHy would I do someone to offend someone who is helping me? Truth is, i
wouldn't.
Oh well so be it.


.


Ken Slovak - [MVP - Outlook] March 29th 10 02:08 PM

Create a macro in Outlook to run a rule
 
I have no idea what's wrong. From what you've said none of the object such
as NameSpace or the Rules collection are ever anything other than Nothing.
That's why the code isn't running, but I don't know why. I've never seen any
situation like what you describe.

Let's see if we can get any code to run at all. Put this in the same code
module you have your rules code:

Sub Test
MsgBox "This is a test"
End Sub

Put your cursor on the MsgBox line and press F5. Do you get the MsgBox
dialog?

--
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" wrote in message
...
Ken:
First, I went to someone else b/c I left my reply on 3/16 and had not
heard
anyting and gave up on 3/22, that is why I tried someone else.

Secondly, I gave you all these security settings already in an earlier
post.
from 3/16 but here it is again: So I'll do it this way:
Yes, OUtlook 2007, no errors, when I run the macro through OUtlook, it
opens
VB and highlights the Setcol Rules line, that is it, not errors

Programming says "warn me about suspicious.....(recommended)"

Warnings for all macros
Warn me about suspecious activity when my , etc etc
Bottom line, is that you wrote the program, not me, and I used a lot of
time
to figure out what you were asking and tried to answer the best of my
ability. I gave up b/c I had not heard from you in 6 days, hey maybe you
were on vacation, but I just figured you got ****ed off and was frustrated
that I was SO dumb about this.

My rule runs fine manually, it is call Delete Spam, I copied and pasted
your
programming into VBA, enabled macros. Opened the junk folder, clicked on
macros, run the delete spam macro and all it does is highlight my first
e-mail in the junk folder, no errors nothing.

So maybe delete everything and start over. I have not gotten a response
from my other posts, just ignored me, oh well, so be it.
So whatever you want to do is fine with me.


You wrote:

The first thing, before any rules stuff, is that you should be getting a
valid NameSpace object. I If you aren't then something is drastically
wrong
that must be corrected before any of your code will run at all. I'd be
curious about the security settings as I asked, and I'd also be curious to
see if you are running an anti-virus program that maybe is breaking code
with a script stopper.
I don't know what a valid NameSpace object looks like
I do run an anti-virus program called Avira, I can look to see if it is
stopping scripts but doubt it b/c I would have other indications of this,
don't you think?
Sorry about all this, but I just thought that you had given up on me!



DLGolfs March 29th 10 09:12 PM

Create a macro in Outlook to run a rule
 
Here is what I have in the VBA:
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

Sub Test()
MsgBox "This is a test"
End Sub

When I put the cursor at the new sub Test() it runs and a dialog box opens
that says "this is a test"
When I put the cursor at the beginning of subrunrule, then it gives me a 438
error, I hit debug and highlights the setcolrules line in the second section.

Hope that helps you



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

I have no idea what's wrong. From what you've said none of the object such
as NameSpace or the Rules collection are ever anything other than Nothing.
That's why the code isn't running, but I don't know why. I've never seen any
situation like what you describe.

Let's see if we can get any code to run at all. Put this in the same code
module you have your rules code:

Sub Test
MsgBox "This is a test"
End Sub

Put your cursor on the MsgBox line and press F5. Do you get the MsgBox
dialog?

--
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" wrote in message
...
Ken:
First, I went to someone else b/c I left my reply on 3/16 and had not
heard
anyting and gave up on 3/22, that is why I tried someone else.

Secondly, I gave you all these security settings already in an earlier
post.
from 3/16 but here it is again: So I'll do it this way:
Yes, OUtlook 2007, no errors, when I run the macro through OUtlook, it
opens
VB and highlights the Setcol Rules line, that is it, not errors

Programming says "warn me about suspicious.....(recommended)"

Warnings for all macros
Warn me about suspecious activity when my , etc etc
Bottom line, is that you wrote the program, not me, and I used a lot of
time
to figure out what you were asking and tried to answer the best of my
ability. I gave up b/c I had not heard from you in 6 days, hey maybe you
were on vacation, but I just figured you got ****ed off and was frustrated
that I was SO dumb about this.

My rule runs fine manually, it is call Delete Spam, I copied and pasted
your
programming into VBA, enabled macros. Opened the junk folder, clicked on
macros, run the delete spam macro and all it does is highlight my first
e-mail in the junk folder, no errors nothing.

So maybe delete everything and start over. I have not gotten a response
from my other posts, just ignored me, oh well, so be it.
So whatever you want to do is fine with me.


You wrote:

The first thing, before any rules stuff, is that you should be getting a
valid NameSpace object. I If you aren't then something is drastically
wrong
that must be corrected before any of your code will run at all. I'd be
curious about the security settings as I asked, and I'd also be curious to
see if you are running an anti-virus program that maybe is breaking code
with a script stopper.
I don't know what a valid NameSpace object looks like
I do run an anti-virus program called Avira, I can look to see if it is
stopping scripts but doubt it b/c I would have other indications of this,
don't you think?
Sorry about all this, but I just thought that you had given up on me!


.


Ken Slovak - [MVP - Outlook] March 30th 10 02:17 PM

Create a macro in Outlook to run a rule
 
OK, so at least some VBA code can run.

Let's try adding additional testing and error handling to see more of what's
going on here. I'm still mystified as to what's happening. You are running
in Outlook 2007, correct?

Sub RunRuleDeleteSpam2()
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")
If Not (oNs Is Nothing) Then
Set oStore = oNS.DefaultStore
If Not (oStore Is Nothing) Then
Set colRules = oStore.Rules()
If Not (colRules Is Nothing) Then
Set oRule = colRules.Item("Delete Spam")
If Not (oRule Is Nothing) Then
oRule.Execute
Else
MsgBox "Rule Delete Spam is nothing"
End If
Else
MsgBox "Rules collection is nothing"
End If
Else
MsgBox "Default Store is nothing"
End If
Else
MsgBox "NameSpace is nothing"
End If
End Sub

Try this new code that provides a little more information. I don't think it
will work or help though, I think something very odd is going on that might
not be possible to figure out via newsgroup posts.

--
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" wrote in message
...
Here is what I have in the VBA:
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

Sub Test()
MsgBox "This is a test"
End Sub

When I put the cursor at the new sub Test() it runs and a dialog box opens
that says "this is a test"
When I put the cursor at the beginning of subrunrule, then it gives me a
438
error, I hit debug and highlights the setcolrules line in the second
section.

Hope that helps you




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

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com