Today's Lazy Programmer provides an answer for Martin, who asked how to change the font in the Notes field only in Contacts, but not in the other Outlook items types. He also wants to change the font used with existing Contact items.
When you change the font in Options > Mail > Stationery and Fonts, the change is applied to all new Outlook items. Martin wants to use a one font for contacts and another for his email and other Outlook items. (Sticky notes have their own font settings and don't use Word as the editor.)
One option is to use custom stationery for your email messages. While this works fine if you want to use one font for everything except email, since Outlook now uses Word as the email editor, you can use Word VBA to change the font in the notes field in any new item type except email and sticky notes. This code sample shows you how.
This works on new items only, it will not change the font in existing items.
I'm starting with Michael Bauer's Inspector: Edit new items code sample and adding a few lines to set the font. Now when I open any new Outlook item (but not a new message or sticky note), the body font is changed. In my example (so we can easily see that it works), I'm using Wingdings (and size 18 font). Replace it with a font name as seen in the Font selector. (You can use lower case names as the font name is not case-sensitive.)
This is an Application_Startup macro. Paste it into ThisOutlookSession and set a reference to the Microsoft Word Object Library in Tools, References. To test it without restarting Outlook you'll need to click in Application_Startup and click the Run button. Oh, and macro security needs to be set to Low during testing and the macro signed once you're satisfied with it. How to use Outlook’s VBA Editor has more information if you are new to VBA.
Private WithEvents m_Inspectors As Outlook.Inspectors Private WithEvents m_Inspector As Outlook.Inspector 'http://slipstick.me/888jf Private Sub Application_Startup() Set m_Inspectors = Application.Inspectors End Sub Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector) Set m_Inspector = Inspector End Sub ' Set a reference to Word object model in ' Tools, References Private Sub m_Inspector_Activate() ' Sticky notes don't use Word editor, so we need check for Notes too If m_Inspector.CurrentItem.Class = olMail Or m_Inspector.CurrentItem.Class = olNote Then Exit Sub Else Dim olInspector As Outlook.Inspector Dim olDocument As Word.Document Dim olSelection As Word.Selection Set olInspector = Application.ActiveInspector() Set olDocument = olInspector.WordEditor Set olSelection = olDocument.Application.Selection With olSelection.Font .Name = "wingdings" .Size = 18 End With ' Delete this line after testing olSelection.InsertBefore olSelection.Font.Name & " your sample text" Set m_Inspector = Nothing End Sub
Change the font for only one item type
If, like Martin, you only want to change the font for one Outlook item type, the If... then statement looks for the item type and changes the font. Other types are not touched.
Replace the m_Inspector_Activate() sub with the following code:
Private Sub m_Inspector_Activate() 'http://slipstick.me/888jf If m_Inspector.CurrentItem.Class = olContact Then Dim olInspector As Outlook.Inspector Dim olDocument As Word.Document Dim olSelection As Word.Selection Set olInspector = Application.ActiveInspector() Set olDocument = olInspector.WordEditor Set olSelection = olDocument.Application.Selection With olSelection.Font .Name = "wingdings" .Size = 18 End With ' Used during testing olSelection.InsertBefore olSelection.Font.Name & " your sample text" End If Set m_Inspector = Nothing End Sub
|New item type||Object class name|
|Note (sticky note)||olNote|
Change the formatting of selected items
This code changes the font in the body of selected appointment, contact, or task items. To use, select the items (it's easier to use a list view, especially for appointments) then run the code. Each item will quickly open then close as Outlook makes the changes.
I recommend selecting some items, then Ctrl+C, V to create a copy of the items for testing.
Public Sub ChangeFormatting() ' http://slipstick.me/888jf Dim currentExplorer As Explorer Dim Selection As Selection Dim obj As Object Dim objWord As Word.Application Dim objDoc As Word.Document Dim objSel As Word.Selection On Error Resume Next Set currentExplorer = Application.ActiveExplorer Set Selection = currentExplorer.Selection For Each obj In Selection Set objItem = obj objItem.Display Set objInsp = objItem.GetInspector Set objDoc = objInsp.WordEditor Set objWord = objDoc.Application Set objSel = objWord.Selection objSel.WholeStory With objSel.Font .Name = "broadway" .Size = 12 .Color = wdColorGreen End With objItem.Close olSave Err.Clear Next Set currentExplorer = Nothing Set obj = Nothing Set Selection = Nothing End Sub