One of the tips we shared with our Outlook Daily Tips readers was how to use a Run a Script Rule to change the font used with RSS feeds.
Note that this will not work with Outlook 2007 RSS Feeds as it does not support PostItems in Run a Script rules. You can use Run a script rules with MailItems. You need to use ItemAdd event handler with Outlook 2007's RSS Feeds.
A user disliked Calibri font and wanted to change it but gave up after changing fonts "everywhere" in both Outlook and Internet Explorer and not affecting the RSS feed font. He posted the question in a forum and no one there knew either, so I asked the people who worked on the RSS feature at Microsoft. The answer: The font is not exposed to end-users.
The user thought that maybe it would be possible to do it using a Run-a-script rule but had no idea how to write the script. Outlook Developer MVP Michael Bauer of https://vboffice.net/ supplied the code to make it work. (Michael has quite a few useful code samples on his site BTW.)
We first check the message source so we can see how the font is set.
<!-- body {font-family:"Calibri";} -->
Because its hard-coded in the message, changing fonts in Outlook won't help; we need to change the message source. Fortunately, a run a script rule can change it.
The Solution
Begin by pasting the code into ThisOutlookSession in the VB Editor.
Open the VB Editor (Alt+F11), expand the folders on the left to locate ThisOutlookSession, then double click to open it on the right side of the screen. Copy the code and paste it into ThisOutlookSession. The code colors should be black, blue and green. If any lines are red, there is a error.
Public Sub ChangeRSSFont(Item As PostItem) Dim b$, NewFont$, OldFont$ OldFont = "{font-family:" & Chr(34) & "Calibri" & Chr(34) & ";}" NewFont = "{font-family:" & Chr(34) & "Times New Roman" & Chr(34) & ";}" b = Item.HTMLBody b = Replace(b, OldFont, NewFont, , , vbTextCompare) Item.HTMLBody = b Item.Save End Sub
Next, you'll create a Rule that applies to any RSS feed, with the Run a Script action, selecting the ChangeRSSFont macro.
As new RSS feeds arrive, the font will be changed from Calibri the font of your choosing (Times New Roman, in our sample).
Can you change more than the font? Sure. It's just CSS so you can use any CSS attribute that is supported in the Body tag.
One useful change is to a larger font. For this you will add the font-size attribute to the NewFont code:
NewFont = "{font-family:" & Chr(34) & "Times New Roman" & Chr(34) & ";font-size:14pt;}"
Any valid font-size will work, including %, pt, px, large, or larger.
Changing Email Fonts
Note: This is supported by the Run a Script rule in all versions of Outlook. If you don't have the run a script action, see "Run-a-Script Rules Missing in Outlook"
You can use also use this code to change the fonts on incoming email messages, but it will be hit-or-miss as each client uses different, often multiple, font-families.
First, you will need to change "(Item As PostItem)" to "(Item As MailItem)" and get the correct line for the OldFont from the message source and format the NewFont appropriately.
Because the code can vary so much and because when multiple fonts are listed, the first is used if it exists, you can replace just the first part of the attribute and it will apply to most messages using the old font. You could even replace just the font name, but this could have unexpected results.
To replace just this part of the code:
font-family:"Calibri"
Your NewFont and OldFont code will look like this:
OldFont = "font-family:" & Chr(34) & "Calibri" & Chr(34)
NewFont = "font-family:" & Chr(34) & "Times New Roman" & Chr(34)
To use, paste the code below into the VBA Editor, change the fonts as needed then create a Rule using the Run a Script action, selecting the ChangeMailFont macro.
As messages arrive meeting your conditions, the font will be changed from Calibri the font of your choosing (Comic Sans in this sample).
Public Sub ChangeMailFont(Item As MailItem) Dim b$, NewFont$, OldFont$ OldFont = "font-family:" & Chr(34) & "Calibri" & Chr(34) NewFont = "font-family:" & Chr(34) & "Comic Sans" & Chr(34) b = Item.HTMLBody b = Replace(b, OldFont, NewFont, , , vbTextCompare) Item.HTMLBody = b Item.Save End Sub
Testing the Macro
Use this stub macro to test your code. Select a message, then run this macro. It calls the macro that actually makes the changes.
Sub TestMacro() Dim objApp As Outlook.Application Dim objItem As Object ' MailItem Set objApp = Application Set objItem = objApp.ActiveExplorer.Selection.Item(1) 'macro name you want to run goes here ChangeMailFont objItem End Sub
Note that this is a work in progress and at this time works only on the RSS feeds that are delivered to a subfolder named RSS.
Using ItemAdd handler
This code runs when Outlook starts and processes new items (RSS feeds in this case) as they arrive and includes the font-size code, which you can remove (leaving just ";}", if desired. It will work with any version of Outlook (change the folder you are watching), but is required if you want to change Outlook 2007 RSS feeds.
Option Explicit Private WithEvents olPostItems As Items Private Sub Application_Startup() Dim objNS As NameSpace Dim objRss As Outlook.MAPIFolder Dim objRSSFolder As Outlook.MAPIFolder Set objNS = Application.Session Set objRss = objNS.GetDefaultFolder(olFolderRssFeeds) Set objRSSFolder = objRss.Folders.Item("RSS") Set olPostItems = objRSSFolder.Items Set objNS = Nothing End Sub Public Sub olPostItems_ItemAdd(ByVal Item As Object) Dim b$, NewFont$, OldFont$ If LCase(Item.MessageClass) = "ipm.post.rss" Then NewFont = "{font-family:" & Chr(34) & "Times New Roman" & Chr(34) & ";font-size:14pt;}" OldFont = "{font-family:" & Chr(34) & "Calibri" & Chr(34) & ";}" b = Item.HTMLBody b = Replace(b, OldFont, NewFont, , , vbTextCompare) Item.HTMLBody = b Item.Save End If End Sub
More Information
More Run a Script Samples:
- Autoaccept a Meeting Request using Rules
- Automatically Add a Category to Accepted Meetings
- Blocking Mail From New Top-Level Domains
- Convert RTF Messages to Plain Text Format
- Create a rule to delete mail after a number of days
- Create a Task from an Email using a Rule
- Create an Outlook Appointment from a Message
- Create Appointment From Email Automatically
- Delegates, Meeting Requests, and Rules
- Delete attachments from messages
- Forward meeting details to another address
- How to Process Mail After Business Hours
- Keep Canceled Meetings on Outlook's Calendar
- Macro to Print Outlook email attachments as they arrive
- Move messages CC'd to an address
- Open All Hyperlinks in an Outlook Email Message
- Outlook AutoReplies: One Script, Many Responses
- Outlook's Rules and Alerts: Run a Script
- Process messages received on a day of the week
- Read Outlook Messages using Plain Text
- Receive a Reminder When a Message Doesn't Arrive?
- Run a script rule: Autoreply using a template
- Run a script rule: Reply to a message
- Run a Script Rule: Send a New Message when a Message Arrives
- Run Rules Now using a Macro
- Run-a-Script Rules Missing in Outlook
- Save all incoming messages to the hard drive
- Save and Rename Outlook Email Attachments
- Save Attachments to the Hard Drive
- Save Outlook Email as a PDF
- Sort messages by Sender domain
- Talking Reminders
- To create a rule with wildcards
- Use a Macro to Copy Data in an Email to Excel
- Use a Rule to delete older messages as new ones arrive
- Use a run a script rule to mark messages read
- Use VBA to move messages with attachments
Currently Outlook 2010 Win7. I use 3 different email addresses, one profile, one pst file, 3 accounts. I would like when I receive mail to have the emails from the 3 be colored differently for easy identification. I remember in outlook express, I could do this. I don't see an option/feature for this in Rules. Can you help? Thanks, Ron
Create a customized view using Conditional Formatting to highlight messages by account. See https://www.slipstick.com/tutorial/use-automatic-formatting-to-highlight-messages/ for instructions.