Class AutoFormatRule (Outlook VBA)
The class AutoFormatRule represents a formatting rule used by a View object to determine how to format Outlook items displayed within that view. To use a AutoFormatRule class variable it first needs to be instantiated, for example
Dim afr as AutoFormatRule
Set afr = Session.CreateSharingItem.Move.Views(1).AutoFormatRules(Index:=1)
For Each
Here is an example of processing the AutoFormatRule items in a collection.
Dim afr As AutoFormatRule
For Each afr In Session.CreateSharingItem.Move.Views(1).AutoFormatRules
Next afr
Class
Returns an OlObjectClass constant indicating the object's class. Here you can find possible values for
Dim oocsClass As OlObjectClass
oocsClass = Session.CreateSharingItem.Move.Views(1).AutoFormatRules(1).Class
Enabled
Returns or sets a Boolean value that indicates whether the formatting rule represented by the AutoFormatRule object is enabled.
Session.CreateSharingItem.Move.Views(1).AutoFormatRules(1).Enabled = True
Filter
Returns or sets a String value that represents the filter for a custom formatting rule.
The value of this property is a DAV Searching and Locating (DASL) string that represents the current filter for the custom formatting rule. For more information about using DASL to filter items formatted by the formatting rule, see Filtering Items. Setting this property to an empty string applies the custom formatting rule to all items displayed by the view.
Private Sub FormatHandoffMessages()
Dim objView As TableView
Dim objRule As AutoFormatRule
' Check if the current view is a table view.
If Application.ActiveExplorer.CurrentView.ViewType = olTableView Then
' Obtain a TableView object reference to the current view.
Set objView = Application.ActiveExplorer.CurrentView
' Create a new rule that displays any message with a
' subject line that starts with "HANDOFF" in
' blue, bold, 8 point Courier New text.
Set objRule = objView.AutoFormatRules.Add("Handoff Messages")
With objRule
.Filter = """http://schemas.microsoft.com/mapi/proptag/0x0037001f""" & _
" CI_STARTSWITH 'HANDOFF'"
With .Font
.Name = "Courier New"
.Size = "8"
.Bold = True
.Color = olColorBlue
End With
End With
' Save and apply the table view.
objView.Save
objView.Apply
End If
End Sub
Font
Returns a ViewFont object that represents the font used to display Outlook items that satisfy the conditions for the formatting rule in the view.
Session.CreateSharingItem.Move.Views(1).AutoFormatRules(1).Font =
Name
Returns or sets a String value that represents the display name for the object.
Session.CreateSharingItem.Move.Views(1).AutoFormatRules(1).Name =
Session
Returns the NameSpace object for the current session.
The Session property and the GetNamespace method can be used interchangeably to obtain the NameSpace object for the current session. Both members serve the same purpose. For example, the following statements perform the same function:
Standard
Returns a Boolean value that indicates whether the AutoFormatRule object represents a built-in Outlook formatting rule.
If the value of this property is set to True, then the Filter and Name properties of the AutoFormatRule object cannot be changed. Similarly, you cannot use the Remove method of the AutoFormatRules collection to delete a built-in Outlook formatting rule, nor can you use the Insert method of the AutoFormatRules collection to insert a custom formatting rule above or between the built-in Outlook formatting rules contained by that collection.
Private Sub DisableCustomAutoFormatRules()
Dim objTableView As TableView
Dim objRule As AutoFormatRule
' Check if the current view is a table view.
If Application.ActiveExplorer.CurrentView.ViewType = olTableView Then
' Obtain a TableView object reference to the current view.
Set objView = Application.ActiveExplorer.CurrentView
' Enumerate the AutoFormatRules collection for
' the table view, disabling any custom formatting
' rule defined for the view.
For Each objRule In objView.AutoFormatRules
If Not objRule.Standard Then
objRule.Enabled = False
End If
Next
' Save and apply the table view.
objView.Save
objView.Apply
End If
End Sub