Reputation: 21
I'm trying to create AutoFormatRules for my Outlook calendar through VBA, and running into several issues.
Here's my POC code:
Public Sub CreateAutoFormatRule()
Dim afr As Outlook.AutoFormatRule
Set afr = Outlook.ActiveWindow.CurrentView.AutoFormatRules.Add("Test2")
With afr
.Filter = """urn:schemas:httpmail:subject"" LIKE '%Poe%'"
.Enabled = True
.Font.Bold = True
End With
End Sub
First problem I run into is that this code does nothing at all. It runs without error, but no autoformat rule is added to my current view; it doesn't show up in the autoformat dialog. And when I iterate through the AutoFormatRules collection, the Test2 rule is not listed.
What am I missing here?
(Follow-on problem is that the AutoFormatRule object seems to support only font-related formatting. What I want is to color appointments based on words in the subject line, but while this is supported in the front-end, the object model seems to know nothing about it.)
(Ultimate goal is to create code to export my custom autoformatting to XML, and to read the XML to recreate the rules in another instance of Outlook. But if even creating an AFR runs into such problems, I'm pessimistic about the Master Plan.)
Upvotes: 0
Views: 112
Reputation: 21
Okay, that one was easy. The only thing lacking was saving the current view after adding the rule:
Outlook.ActiveWindow.CurrentView.Save
With that command added, the newly created view is added to the collection and to the UI dialog.
Upvotes: 0