A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Create a macro in Outlook to run a rule



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old March 28th 10, 02:24 PM posted to microsoft.public.outlook.program_vba
DLGolfs
external usenet poster
 
Posts: 25
Default 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.


.

  #2  
Old March 29th 10, 02:08 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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!


  #3  
Old March 29th 10, 09:12 PM posted to microsoft.public.outlook.program_vba
DLGolfs
external usenet poster
 
Posts: 25
Default 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!


.

  #4  
Old March 30th 10, 02:17 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2007 rule won't start a macro Dmitry Sotnikov Outlook and VBA 1 August 1st 08 04:57 PM
Create a Macro in Outlook Bert Outlook and VBA 10 July 2nd 08 08:32 PM
Run macro through rule Flash08 Outlook - General Queries 2 December 20th 07 04:16 PM
create Macro, Outlook 2007 - create is grayed out Dave Horne[_2_] Outlook - General Queries 2 November 4th 07 09:45 AM
Create a macro that runs from a Rule CF_business_analyst Outlook and VBA 8 January 13th 06 05:12 PM


All times are GMT +1. The time now is 06:11 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-2025 Outlook Banter.
The comments are property of their posters.