Outlook自动格式化规则VBA空过滤器

时间:2015-07-20 08:03:00

标签: vba outlook outlook-vba

我尝试在OUTLOOK 2013下自动添加 Autoformat规则

规则已创建...但过滤器为空!!

这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

您可能需要启用规则,您还可以尝试使用Chr()功能替换特殊字符:

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

以下是修改后的代码:

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