2015-07-20 62 views
0

我嘗試自動添加自動套用格式規則展望2013年展望Autformat規則VBA空濾

的創建規則下......但過濾是空的!

這是我的代碼:

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

您可能需要啓用規則,你也可以嘗試使用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 
+0

謝謝您重新申請!沒有更多出現,標準仍然是空的......! – Vincent

+0

Mkay ...對不起沒有幫助你...我看不到這可能來自哪裏... – R3uK

+1

這是一個已知問題,outlook不保存AutoFormatRule.Filter屬性(當從代碼使用它時, UI工作正常)。 https://social.msdn.microsoft.com/Forums/en-US/3b4a0cf8-dba9-417a-94c3-7be4340a5961/outlook-2010-autoformatrulefilter-property-not-saving?forum=outlookdev – user1016945