Format VBA Code Examples in Blog Post

On the Contextures blog, Gregory suggested using the WordPress plugin, CodeColorer, for formatting the Excel VBA code examples.

In Twitter, Dick Kusleika said that he’s using CodeColorer too, and it works well. I decided to test the plug-in here, before installing it on the Contextures blog.

The CodeColorer feature list looks promising, especially these items:

  • syntax highlighting of code in comments
  • code protect from mangling by WordPress (for example, quotes, double-dashes, etc would look just right as you entered)

Installing the CodeColorer Plugin

The installation was quick and easy, using the WordPress dashboard. After activating the plugin, I went to the its settings page, to see what could be adjusted. What’s the fun in having a new toy, if you don’t try to break it?

CodeColorer01

There is a preview of the code, at the bottom of the settings panel. I changed the Theme, from the default of Slush and Poppies(!) to Vibrant Ink. The preview only changed after I clicked the Save Options button.

Yikes! That’s not the look I’m going for.

CodeColorer02

Twitlight (yes, TwiTlight), looked about the same. At the other end of the code formatting scale, Dawn is a bit too subtle.

CodeColorer03

So, back to Slush and Poppies it is. Is it just me, or would Slush and Puppies be a better name?

CodeColorer04

The Formatted Code

Here’s the snippet of code that I copied from Excel VBA.

Sub DeleteCustomLists()
' built in lists are not deleted
Dim n As Long

n = Application.CustomListCount
On Error Resume Next
For n = n To 1 Step -1
Application.DeleteCustomList ListNum:=n
Next n
End Sub

And this is how it looked in Excel

CodeColorer05

Formatted Code in Comments

The CodeColorer plugin is supposed to format the code in the comments too. You can test it here, and please let me know if you have any trouble, or suggestions.

To format your code in the comments, use this syntax:

CodeColorer06

Thanks!

______________

4 thoughts on “Format VBA Code Examples in Blog Post”

  1. Hey, I told DK about that plugin. I’ve been using it for some time now. I like that you can customize the width for RSS, because generally you can afford to make code snippets wider in your feed because you don’t have the sidebar. I did add some CSS to change some of the font sizes, however.

    1. @JP, thanks, and I haven’t played with the CSS yet, but I’ll give it a try.

      And in Dick’s defence, he probably didn’t remember where he heard about the plugin. Wait a couple of years, and you’ll know what I mean!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.