Removing Comic Sans From Messages in Outlook Rules

I started a new job this week. In completely unrelated news, I was strongly motivated this evening to figure out how to remove Comic Sans from inbound email automatically. It turns out that it’s actually pretty simple. However, much like Picasso spending 50 years to learn to do a sketch in 30 seconds, it actually took me a bit of digging to understand how this “simple” solution is put into place.

For people who already have that understanding, here’s my solution:

  1. Create this Macro:
  2. Sub StripComicSans(Item As Outlook.MailItem)
        Item.HTMLBody = Replace(Item.HTMLBody, "Comic Sans MS", "Calibri")
        Item.Close olSave
    End Sub
  3. Create a custom rule with “run a script” as one of the actions, with the above script selected

Simple right? Well, maybe. Personally, without a lot of windows programming experience (no, not even VBA) there are a lot of gaps and assumed knowledge in that list of steps. So, here’s a more detailed list of steps I took, including URLs that pointed me in the right direction along the way.

1. Make sure Visual Basic for Applications is installed

I don’t have much to add to this because my office suite came with VBA installed. I don’t even know if it’s an extra cost, but to get this method to work it is definitely needed.

2. Make sure the Developer tab is enabled in Outlook

I found the clearest explanation for this in the Getting Started with VBA in Outlook 2010 MSDN article:

  1. On the File tab, choose Options to open the Outlook Options dialog box.
  2. Click Customize Ribbon on the left side of the dialog box.
  3. Under Choose commands from on the left side of the dialog box, select Popular Commands.
  4. Under Customize the ribbon on the right side of the dialog box, select Main tabs, and then select the Developer check box.
  5. Click OK.

3. Enable macros

Remember how once upon a time macros were the root of all evil? Good times, right? Well, in order for Outlook to even consider running your macro you have to change the default settings. By default Outlook is set to notify (ask you permission to run) signed macros, and to ignore unsigned macros. This seems to even apply to macros you write yourself. There are instructions for changing this in the previously mentioned MSDN article, but there is an easier way:

  1. Click the Developers tab.
  2. Click the Macro Security button.
  3. Select Notifications for all macros option.
  4. Click OK.

I saw several comments that Outlook needed to be restarted for these Macro setting changes to take effect. I can’t confirm this because I had several other problems during this process that caused me to restart anyway. If it’s not working, restarting Outlook might be worth a try.

4. Create the new macro

I was a little bit confused by this step, and I’m not sure I did the Right Thing, but what I did worked:

  1. Open the MS VBA editor by clicking the Visual Basic icon in the Developer tab.
  2. Expand the Microsoft Outlook Objects folder in the Project pane.
  3. Select the ThisOutlookSession item from the Project pane.
  4. Paste in the macro and save

Again, the specific Macro is:

Sub StripComicSans(Item As Outlook.MailItem)
    Item.HTMLBody = Replace(Item.HTMLBody, "Comic Sans MS", "Calibri")
    Item.Close olSave
End Sub

The basic outline of this macro came from a answer, but the answer was incomplete. If the MailItem isn’t saved after editing, the changes won’t be reflected in Outlook. It took me a bit of debugging to figure that out, and the MSDN MailItem Object Members page was very useful.

5. Assign the macro to a custom rule

My goal when starting this was to have a rule that was applied automatically, but with a very narrow scope. I believe that some formatting is valuable (even Comic Sans, potentially, if used on purpose by a designer) so I don’t want to remove it wholesale (which is also why I’m not using the “convert inbound mail to plaintext” solution). As such, I am limiting the rule only to the sender I know to use Comic Sans in all emails. I can always change it later.

  1. In Home tab, click Rules -> Create Rule.
  2. Click Advanced Options.
  3. Apply any desired limiting condition(s). In production I limited it to only run for the specific sender, and in testing I set it to only run for emails that I sent (so I could send emails to myself). After setting the condition(s), click Next.
  4. “Check” the run a script action.
  5. In the Step 2 box, click the blue a script text to choose the macro to run.
  6. In the Select Script dialog select the StripComicSans macro, which will likely be the only item in the list, click OK.
  7. Click Next.
  8. Add any exceptions if needed, click Next.
  9. Name the rule, then click Finish

6. Enjoy a twinkie

That’s pretty much it. If you’re still testing, you should be able to send yourself an email with Comic Sans in it, and after receiving it the Comic Sans will be removed.

A couple of troubleshooting/usage comments:

  • If you can’t tell if the rule is even running, try a line like MsgBox "Mail message arrived: " & Item.Subject in your macro. This is very simple and will provide instant feedback on whether your rule is even being evaluated
  • If you have a typo in your script, VBA will hang processing your macro. My assumption was that the rule would simply be skipped, but in fact all inbound mail flow that matches your rule will stop until you fix the script and restart the macro by pressing the green “play” icon or pressing F5
  • It appears that once per Outlook session you have to tell it to allow your macro to run. This isn’t a big deal for me (I leave it running all the time), but might be annoying if you have to start and stop it a lot for some reason. Outlook will prompt you the first time, post start, you receive an email matching the rule. You can also short circuit that by clicking over to the Developer tab and clicking the Macros button as soon as you start Outlook.
  • I hadn’t realized this before (I bypassed Outlook/Exchange rules early and used imapfilter instead), but you can apply existing rules to mail you have already received also, via the Rules -> Manage Rules & Alerts dialog. This is handy if you received quite a bit of mail before getting frustrated enough to put a solution like this one in place.

I have no been using this macro for a day and it has been performing well. Of course, if past performance predicts future results, I’ll now trip over a “remove comic sans” option in Outlook, but it was still an interesting diversion.

2 thoughts on “Removing Comic Sans From Messages in Outlook Rules

  1. Thank you for saving us from over-enthusiastic office managers everywhere. Next homework assignment: stripping multiple exclamation marks!!!!

Leave a Reply

Your email address will not be published. Required fields are marked *