Outlook 2016 VBA to Run Rules automatically on schedule
up vote
0
down vote
favorite
Trying to run a simple rule to move emails upon arrival from first public email box to second public email box (Rule is: Apply this rule after the message arrives | Sent to "first public email box" | move it to the "second public email box" folder). Rule works when run manually but the rule does not work automatically upon emails arriving (research shows there might be some corrupt file, blah blah). Trying to make it work via VBA instead. Below macro supposed to run the rules upon a reminder popping up. Reminder pops up, but rules don't run. Running that macro from a QAT custom button, brings up progress window, and that window shows progress, but emails are still in the first public email box.
Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass <> "IPM.Task" Then
Exit Sub
End If
If Item.Subject = "Run Rules" Then
RunRules
End If
End Sub
Sub RunRules()
Dim olRules As Outlook.Rules
Dim myRule As Outlook.Rule
Dim olRuleNames() As Variant
Dim name As Variant
olRuleNames = Array("Rule A", "Rule B")
Set olRules = Application.Session.DefaultStore.GetRules()
For Each name In olRuleNames()
For Each myRule In olRules
' Rules we want to run
If myRule.name = name Then
myRule.Execute ShowProgress:=True
End If
Next
Next
End Sub
vba outlook
add a comment |
up vote
0
down vote
favorite
Trying to run a simple rule to move emails upon arrival from first public email box to second public email box (Rule is: Apply this rule after the message arrives | Sent to "first public email box" | move it to the "second public email box" folder). Rule works when run manually but the rule does not work automatically upon emails arriving (research shows there might be some corrupt file, blah blah). Trying to make it work via VBA instead. Below macro supposed to run the rules upon a reminder popping up. Reminder pops up, but rules don't run. Running that macro from a QAT custom button, brings up progress window, and that window shows progress, but emails are still in the first public email box.
Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass <> "IPM.Task" Then
Exit Sub
End If
If Item.Subject = "Run Rules" Then
RunRules
End If
End Sub
Sub RunRules()
Dim olRules As Outlook.Rules
Dim myRule As Outlook.Rule
Dim olRuleNames() As Variant
Dim name As Variant
olRuleNames = Array("Rule A", "Rule B")
Set olRules = Application.Session.DefaultStore.GetRules()
For Each name In olRuleNames()
For Each myRule In olRules
' Rules we want to run
If myRule.name = name Then
myRule.Execute ShowProgress:=True
End If
Next
Next
End Sub
vba outlook
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Trying to run a simple rule to move emails upon arrival from first public email box to second public email box (Rule is: Apply this rule after the message arrives | Sent to "first public email box" | move it to the "second public email box" folder). Rule works when run manually but the rule does not work automatically upon emails arriving (research shows there might be some corrupt file, blah blah). Trying to make it work via VBA instead. Below macro supposed to run the rules upon a reminder popping up. Reminder pops up, but rules don't run. Running that macro from a QAT custom button, brings up progress window, and that window shows progress, but emails are still in the first public email box.
Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass <> "IPM.Task" Then
Exit Sub
End If
If Item.Subject = "Run Rules" Then
RunRules
End If
End Sub
Sub RunRules()
Dim olRules As Outlook.Rules
Dim myRule As Outlook.Rule
Dim olRuleNames() As Variant
Dim name As Variant
olRuleNames = Array("Rule A", "Rule B")
Set olRules = Application.Session.DefaultStore.GetRules()
For Each name In olRuleNames()
For Each myRule In olRules
' Rules we want to run
If myRule.name = name Then
myRule.Execute ShowProgress:=True
End If
Next
Next
End Sub
vba outlook
Trying to run a simple rule to move emails upon arrival from first public email box to second public email box (Rule is: Apply this rule after the message arrives | Sent to "first public email box" | move it to the "second public email box" folder). Rule works when run manually but the rule does not work automatically upon emails arriving (research shows there might be some corrupt file, blah blah). Trying to make it work via VBA instead. Below macro supposed to run the rules upon a reminder popping up. Reminder pops up, but rules don't run. Running that macro from a QAT custom button, brings up progress window, and that window shows progress, but emails are still in the first public email box.
Private Sub Application_Reminder(ByVal Item As Object)
If Item.MessageClass <> "IPM.Task" Then
Exit Sub
End If
If Item.Subject = "Run Rules" Then
RunRules
End If
End Sub
Sub RunRules()
Dim olRules As Outlook.Rules
Dim myRule As Outlook.Rule
Dim olRuleNames() As Variant
Dim name As Variant
olRuleNames = Array("Rule A", "Rule B")
Set olRules = Application.Session.DefaultStore.GetRules()
For Each name In olRuleNames()
For Each myRule In olRules
' Rules we want to run
If myRule.name = name Then
myRule.Execute ShowProgress:=True
End If
Next
Next
End Sub
vba outlook
vba outlook
asked Nov 9 at 12:59
Alex
218
218
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The use of DefaultStore is a hint there are stores other than the default.
Set olRules = Application.Session.DefaultStore.GetRules()
Option Explicit
Private Sub FindStoreWithRules()
Dim colStores As stores
Dim oStore As store
Dim olRules As rules
Dim myRule As Rule
Dim i As Long
Set colStores = Session.stores
For i = 1 To colStores.count
Debug.Print i & ": " & colStores(i)
' On second run
' Enter applicable name then uncomment this line and the End If
' If colStores(i) = "Name of store shown in immediate window" Then
On Error Resume Next
' Where rules not applicable on some stores there is an error.
Set olRules = colStores(i).GetRules()
' Discontinue error bypass as soon as the purpose is served
On Error GoTo 0
If Not olRules Is Nothing Then
For Each myRule In olRules
' Uncomment on second run to see if what rules were found
'Debug.Print " - " & myRule.name
Next
Else
Debug.Print "Rules not applicable in " & colStores(i)
End If
' End If
Next
Debug.Print "Done."
End Sub
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The use of DefaultStore is a hint there are stores other than the default.
Set olRules = Application.Session.DefaultStore.GetRules()
Option Explicit
Private Sub FindStoreWithRules()
Dim colStores As stores
Dim oStore As store
Dim olRules As rules
Dim myRule As Rule
Dim i As Long
Set colStores = Session.stores
For i = 1 To colStores.count
Debug.Print i & ": " & colStores(i)
' On second run
' Enter applicable name then uncomment this line and the End If
' If colStores(i) = "Name of store shown in immediate window" Then
On Error Resume Next
' Where rules not applicable on some stores there is an error.
Set olRules = colStores(i).GetRules()
' Discontinue error bypass as soon as the purpose is served
On Error GoTo 0
If Not olRules Is Nothing Then
For Each myRule In olRules
' Uncomment on second run to see if what rules were found
'Debug.Print " - " & myRule.name
Next
Else
Debug.Print "Rules not applicable in " & colStores(i)
End If
' End If
Next
Debug.Print "Done."
End Sub
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
add a comment |
up vote
0
down vote
The use of DefaultStore is a hint there are stores other than the default.
Set olRules = Application.Session.DefaultStore.GetRules()
Option Explicit
Private Sub FindStoreWithRules()
Dim colStores As stores
Dim oStore As store
Dim olRules As rules
Dim myRule As Rule
Dim i As Long
Set colStores = Session.stores
For i = 1 To colStores.count
Debug.Print i & ": " & colStores(i)
' On second run
' Enter applicable name then uncomment this line and the End If
' If colStores(i) = "Name of store shown in immediate window" Then
On Error Resume Next
' Where rules not applicable on some stores there is an error.
Set olRules = colStores(i).GetRules()
' Discontinue error bypass as soon as the purpose is served
On Error GoTo 0
If Not olRules Is Nothing Then
For Each myRule In olRules
' Uncomment on second run to see if what rules were found
'Debug.Print " - " & myRule.name
Next
Else
Debug.Print "Rules not applicable in " & colStores(i)
End If
' End If
Next
Debug.Print "Done."
End Sub
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
add a comment |
up vote
0
down vote
up vote
0
down vote
The use of DefaultStore is a hint there are stores other than the default.
Set olRules = Application.Session.DefaultStore.GetRules()
Option Explicit
Private Sub FindStoreWithRules()
Dim colStores As stores
Dim oStore As store
Dim olRules As rules
Dim myRule As Rule
Dim i As Long
Set colStores = Session.stores
For i = 1 To colStores.count
Debug.Print i & ": " & colStores(i)
' On second run
' Enter applicable name then uncomment this line and the End If
' If colStores(i) = "Name of store shown in immediate window" Then
On Error Resume Next
' Where rules not applicable on some stores there is an error.
Set olRules = colStores(i).GetRules()
' Discontinue error bypass as soon as the purpose is served
On Error GoTo 0
If Not olRules Is Nothing Then
For Each myRule In olRules
' Uncomment on second run to see if what rules were found
'Debug.Print " - " & myRule.name
Next
Else
Debug.Print "Rules not applicable in " & colStores(i)
End If
' End If
Next
Debug.Print "Done."
End Sub
The use of DefaultStore is a hint there are stores other than the default.
Set olRules = Application.Session.DefaultStore.GetRules()
Option Explicit
Private Sub FindStoreWithRules()
Dim colStores As stores
Dim oStore As store
Dim olRules As rules
Dim myRule As Rule
Dim i As Long
Set colStores = Session.stores
For i = 1 To colStores.count
Debug.Print i & ": " & colStores(i)
' On second run
' Enter applicable name then uncomment this line and the End If
' If colStores(i) = "Name of store shown in immediate window" Then
On Error Resume Next
' Where rules not applicable on some stores there is an error.
Set olRules = colStores(i).GetRules()
' Discontinue error bypass as soon as the purpose is served
On Error GoTo 0
If Not olRules Is Nothing Then
For Each myRule In olRules
' Uncomment on second run to see if what rules were found
'Debug.Print " - " & myRule.name
Next
Else
Debug.Print "Rules not applicable in " & colStores(i)
End If
' End If
Next
Debug.Print "Done."
End Sub
answered Nov 9 at 16:53
niton
5,38171941
5,38171941
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
add a comment |
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
On the first run in Immediate window it printed 11 mailbox names, one is mine and 10 Public. Under one that I am trying to automate running the rules it printed "Rules not applicable in Public Folders - ABC@domain.com" On line: Debug.Print i & ": " & colStores(i) – it gave “Run-time error’-2147024891 (80070005)’: You do not have sufficient permission to perform this operation on this object. See the folder contact or your system administrator.” Am I to interpret all that as what I am trying to accomplish is not possible?
– Alex
Nov 9 at 18:16
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
I cannot comment on your permissions. You will have to investigate how you are set up in Outlook. One thing I try to mention on code that fails for shared "mailboxes". Try adding an account if you have only a mailbox michev.info/Blog/Post/1507
– niton
Nov 9 at 19:06
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226169%2foutlook-2016-vba-to-run-rules-automatically-on-schedule%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown