I have this code, that create a rule based on inputboxes typed data, creating and assign a category to e-mails that match the rule. The problem is: the rule is not being executed after saving.
The problem is in line
oRule.Execute(True, "\\Henrique E-mails\", True, 0)
and the error is "= Expected"
Anyone could help me? Suggestions on how to improve the code are welcome as well.
Thanks.
HDE
Public Sub Sinistro()
Dim objOutlook As Outlook.Application
Dim colCategories As Outlook.Categories
Dim oCategory As Outlook.Category
Dim categoria As String
num_sinistro = InputBox("Qual o número do SINISTRO?", , A10)
num_aviso = InputBox("Qual o número do AVISO?")
num_chassi = InputBox("Qual o número do CHASSI?")
envolvidos = InputBox("Transportadora e cliente. Ex: Froli e Scania Chile")
categoria = "Sinistro " & num_sinistro & " - Aviso " & num_aviso & " - Chassi " & num_chassi & " - " & envolvidos
'Create category
Set oCategory = Application.Session.Categories.Add(categoria, 1)
'Create rule
Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
Dim colRuleActions As Outlook.RuleActions
Dim oCategoryRuleAction As Outlook.AssignToCategoryRuleAction
Dim oTextCondition As Outlook.TextRuleCondition
Dim oInbox As Outlook.Folder
'Get Rules from Session.DefaultStore object
Set colRules = Application.Session.DefaultStore.GetRules()
'Create the rule by adding a Receive Rule to Rules collection
Set oRule = colRules.Create(categoria, 0)
'Specify the condition in a TextRuleCondition object
'Condition is if the message contains any related number in subject
Set oTextCondition = oRule.Conditions.BodyOrSubject
With oTextCondition
.Enabled = True
.Text = Array(num_sinistro, num_aviso, num_chassi)
End With
'Action is to assign the category
Set oCategoryRuleAction = oRule.Actions.AssignToCategory
With oCategoryRuleAction
.Enabled = True
.Categories = Array(categoria)
End With
'Update the server and display progress dialog
colRules.Save
'Here I want to execute the rule
oRule.Execute(True, "\\Henrique E-mails\", True, 0)
'Create search
Dim sch As Outlook.search
Dim rsts As Outlook.Results
Dim Scope As String
Dim strF As String
Scope = "'\\Henrique E-mails\Inbox','\\Henrique E-mails\Arquivados'"
strF = "urn:schemas-microsoft-comfficeffice#Keywords = '" & categoria & "'"
Set sch = Application.AdvancedSearch(Scope, strF, True)
sch.Save (categoria)
End Sub
The problem is in line
oRule.Execute(True, "\\Henrique E-mails\", True, 0)
and the error is "= Expected"
Anyone could help me? Suggestions on how to improve the code are welcome as well.
Thanks.
HDE
Public Sub Sinistro()
Dim objOutlook As Outlook.Application
Dim colCategories As Outlook.Categories
Dim oCategory As Outlook.Category
Dim categoria As String
num_sinistro = InputBox("Qual o número do SINISTRO?", , A10)
num_aviso = InputBox("Qual o número do AVISO?")
num_chassi = InputBox("Qual o número do CHASSI?")
envolvidos = InputBox("Transportadora e cliente. Ex: Froli e Scania Chile")
categoria = "Sinistro " & num_sinistro & " - Aviso " & num_aviso & " - Chassi " & num_chassi & " - " & envolvidos
'Create category
Set oCategory = Application.Session.Categories.Add(categoria, 1)
'Create rule
Dim colRules As Outlook.Rules
Dim oRule As Outlook.Rule
Dim colRuleActions As Outlook.RuleActions
Dim oCategoryRuleAction As Outlook.AssignToCategoryRuleAction
Dim oTextCondition As Outlook.TextRuleCondition
Dim oInbox As Outlook.Folder
'Get Rules from Session.DefaultStore object
Set colRules = Application.Session.DefaultStore.GetRules()
'Create the rule by adding a Receive Rule to Rules collection
Set oRule = colRules.Create(categoria, 0)
'Specify the condition in a TextRuleCondition object
'Condition is if the message contains any related number in subject
Set oTextCondition = oRule.Conditions.BodyOrSubject
With oTextCondition
.Enabled = True
.Text = Array(num_sinistro, num_aviso, num_chassi)
End With
'Action is to assign the category
Set oCategoryRuleAction = oRule.Actions.AssignToCategory
With oCategoryRuleAction
.Enabled = True
.Categories = Array(categoria)
End With
'Update the server and display progress dialog
colRules.Save
'Here I want to execute the rule
oRule.Execute(True, "\\Henrique E-mails\", True, 0)
'Create search
Dim sch As Outlook.search
Dim rsts As Outlook.Results
Dim Scope As String
Dim strF As String
Scope = "'\\Henrique E-mails\Inbox','\\Henrique E-mails\Arquivados'"
strF = "urn:schemas-microsoft-comfficeffice#Keywords = '" & categoria & "'"
Set sch = Application.AdvancedSearch(Scope, strF, True)
sch.Save (categoria)
End Sub