Vincent
Vincent

Reputation: 1

Outlook Autformat rules VBA empty filter

I try to automatically add Autoformat Rules under OUTLOOK 2013.

The rule is created... but the filter is empty !!

This is my code :

Dim objView As TableView
Dim objRule As AutoFormatRule
If Application.ActiveExplorer.CurrentView.ViewType = olTableView Then
    Set objView = Application.ActiveExplorer.CurrentView
    Set objRule = objView.AutoFormatRules.Add("myRule")
    With objRule
        .Filter = """urn:schemas:httpmail:fromname"" LIKE 'gmail.com%'"
        With .Font
            .Name = "Courier New"
            .Size = "8"
            .Bold = True
            .Color = olColorBlue
        End With
    End With
    objView.Save
    objView.Apply
End If

Upvotes: 0

Views: 413

Answers (1)

R3uK
R3uK

Reputation: 14547

You may need to Enable the rule, and you can also try to replace special characters using the Chr() function :

Sub test_Vincent()
Dim r As String, _
    r2 As String, _
    r3 As String

r = """urn:schemas:httpmail:fromname"" LIKE 'gmail.com%'"
r2 = Chr(34) & "urn:schemas:httpmail:fromname" & Chr(34) & " LIKE 'gmail.com%'"
r3 = Chr(34) & "urn:schemas:httpmail:fromname" & Chr(34) & " LIKE " & Chr(39) & "gmail.com%" & Chr(39)

MsgBox r & vbCrLf & r2 & vbCrLf & r3
End Sub

Here is your amended code :

Sub Full_Vincent()

Dim objView As TableView, _
    objRule As AutoFormatRule

If Application.ActiveExplorer.CurrentView.ViewType <> olTableView Then
Else
    Set objView = Application.ActiveExplorer.CurrentView
    Set objRule = objView.AutoFormatRules.Add("myRule")
    With objRule
        .Filter = Chr(34) & "urn:schemas:httpmail:fromname" & Chr(34) & " LIKE " & Chr(39) & "gmail.com%" & Chr(39)
        .Enabled = True
        With .Font
            .Name = "Courier New"
            .Size = "8"
            .Bold = True
            .Color = olColorBlue
        End With
    End With
    objView.Save
    objView.Apply
End If

    Set objView = Nothing
    Set objRule = Nothing


End Sub

Upvotes: 1

Related Questions