jfexchange
asked on
Run all MSOutlook rules at once
Hello, i have a number of MS Outlook rules which I am trying to run at once. I found a VBS script for this online here: http://www.outlookcode.com/codedetail.aspx?id=1266
However, i get a compilation error when I try to run this script. Can someone advise what the issue might be? Thanks in advance~!
However, i get a compilation error when I try to run this script. Can someone advise what the issue might be? Thanks in advance~!
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next
' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules
' iterate all the rules
For Each rl In myRules
' determine if it's an Inbox rule
If rl.RuleType = olRuleReceive Then
' if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
Next
' tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
ASKER
no i am using 2007; sp1.
ANy of the rules not working properly then:
Chris
Chris
Sub RunAllInboxRules()
Dim st As Outlook.Store
Dim myRules As Outlook.Rules
Dim rl As Outlook.Rule
Dim count As Integer
Dim ruleList As String
'On Error Resume Next
' get default store (where rules live)
Set st = Application.Session.DefaultStore
' get rules
Set myRules = st.GetRules
' iterate all the rules
For Each rl In myRules
on error goto oops
' determine if it's an Inbox rule
If rl.RuleType = olRuleReceive Then
' if so, run it
rl.Execute ShowProgress:=True
count = count + 1
ruleList = ruleList & vbCrLf & rl.Name
End If
oops:
Next
on error goto 0
' tell the user what you did
ruleList = "These rules were executed against the Inbox: " & vbCrLf & ruleList
MsgBox ruleList, vbInformation, "Macro: RunAllInboxRules"
Set rl = Nothing
Set st = Nothing
Set myRules = Nothing
End Sub
ASKER
thanks i ran that, and still go the same error:
PS C:\Users\vista\Desktop> cscript rulesowa.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\vista\Desktop\rul esowa.vbs( 2, 12) Microsoft VBScript compilation error: Expected end of statement
any idea what the issue is? Thanks,
PS C:\Users\vista\Desktop> cscript rulesowa.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\vista\Desktop\rul
any idea what the issue is? Thanks,
I really ought to read more. You mention VBS in your intro but the macro as posted is VBA not VBS. i.e. it should reside in a code module not in a script. Do you need it restructuring for a script, (should be ok) or are you ok to run it from outlook?
Chris
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Chris thanks for looking this over. I also had misread the original URL and thought the snippet was vbs. I was able to run the macro as VBA. Thanks for the conversion over to VBS as well!
Chris