Coding VBA on the Dark Side

Have you ever wanted to change the colour scheme or theme of Excel's Visual Basic Editor? Read on to find out how and start coding on the Dark Side.

Coding VBA on the Dark Side

If you’ve been coding in any modern Development Environment, you may know that many of them come with colour schemes. A surprisingly common question I encounter is “how can I change Excel’s Visual Basic Editor into Dark Mode?” Here’s how . . .

Code Editor Colour Themes

Many modern code editors allow you to change and even customise the colour scheme of the editor.

You can change the background colour as well as the colours of the code itself. You can often go as far as changing the colour of the text – that is, the code – itself.

Here’s an example of PyCharm, a Python editor, with some sample code:

Even better here’s what some colour-coded VBA code would look like in Microsoft’s free editor, Visual Studio Code:

Now before you get too excited, I’ll disappoint you now.

No. You can’t really code and run VBA in Visual Studio Code (It’d be awesome if you could, though).

That’s because VBA requires a host application like Excel or Word or MS Access to run within. On top of which, Visual Studio Code doesn’t have any concept of the Excel Object Model. So any code which references an Excel object such as a range of cells is going to fail immediately.

Bummer.

What you want, is something that looks like this. Proper VBA code in Excel’s Visual Basic Editor (or VBE for short):

Now that’s what we’re talking about.

If that's what you’re after, then I've got some bad news and something else resembling good news.

VBA’s Visual Basic Editor doesn’t have a theme option.

But it does have some capability to change the colours of the module and code within a module.

Given the VBE hasn’t been updated in a decade (or two!), it isn’t as sophisticated as a modern IDE like PyCharm or Visual Studio Code, but you can still achieve the effect like the one above.

Let’s take a look . . .

Going to the (Visual Basic Editor’s) Dark Side

So, if you really, really want to go to the dark side with the VBE, try this . . .
Fire up Excel if she’s not already running. And then meander over the to Visual Basic Editor.

You can click the Visual Basic button on the Developer Ribbon Tab.

Although, if you’re a keyboard shortcut freak like me, it’s way faster to press ALT+F11 on your keyboard.

If you’ve got a code module open already, your screen might look something like this:

Brrr. Cold White. Let’s change that.

So now you’re in the VBE, from the Tools menu choose Options.

This will display the Options screen. Now select the Editor Format tab:

This screen gives you all the options to change the colours.

Let’s take a look at the choices you have in a bit more detail.

The Code Color list has each type of VBA code display you can change.
For example, ‘Normal Text’ is standard VBA text while ‘Keyword Text’ is for VBA keywords like ‘Dim’ and ‘Function’.

Foreground represents the colour of the text itself.

Background represents the colour of the page directly behind the text

Indicator is the colour of any symbol in the margin such as the circle which appears in the margin when you set a break point.

Font is exactly what it says on the tin. It allows you to change the font, although the selection is limited.

How to Customise the Visual Basic Editor Colours

Let’s change the colours so it look like the proper VBA code in Excel’s Visual Basic Editor screenshot above.

1

If it’s not currently open, display the Options screens. In the VBA Editor, from the Tools menu, select Options and then select the Editor Format tab.

2

In the list of Code Colors, select ‘Normal Text’.

3

From the Foreground dropdown list, select ‘Yellow’.

4

From the Background dropdown list select ‘Black’.

5

From the Indicator dropdown, select ‘Auto’.

You now want to repeat this process for each of the colour choices below:

Call me old school, but I like the FixedSys font.

It’s thick and easy to read. Have a play with some of the font options.
When you’re done, click OK.

Depending on which windows you have showing, your screen will look something like this example which also shows a Break Point and a code syntax error:

The first thing you’ll notice is that Excel does not apply your fancy colour scheme to the entire Visual Basic Editor.

In fact, Excel only changes the main code window and the Immediate Window.

Hmm, not what I was hoping for. How about you?

However if you hiding all the other windows and just leave the main code window visible with the menu and toolbars showing, you can end up with something like this:

Admittedly I’m not one to claim any form of “colour co-ordination skills” so you’ll probably want to experiment with some colour combinations or copy the colours from your favourite ‘modern’ code editor. Note however, that the selection of colours is fixed and you can’t edit them.

If after all your experimenting with colours you decide you’d prefer the original colour, you can always set them back to the default.

Unfortunately, you’ll have to do that manually as well. It’s a shame there’s no option so save a colour combination as a ‘theme’.

If you do decide you’d prefer to code VBA on the ‘Light Side’, here’s the colour scheme so you can change it back:

The whole process is a little tedious, I know, and you’ll probably need to experiment a little to get the “look” you’re after.

Third Party Tools to Customise the VBE Editor Colours

If you want more control over the Visual Basic Editor Colour than what Microsoft grant you, you also have some third-party tools available.

FMS Total Visual CodeTools

FMS, who have been making excellent VBA-related development tools for decades have a product called Total Visual CodeTools. This includes a ‘VBE Color Scheme Manager’ so you can “easily see and set colors for your editor”.

It may not have the ability to edit the colours, but it allows you to save colour schemes and see the affect of the changes as you make them.

VBE Theme Editor

Meanwhile a SuperUser contributor Dimitri Mitropoulos (a.k.a. Gallaux) created a GitHub project called VBE Custom Colors. Dimitri even made the source code available if you want to have a play with it.

The really cool thing about the VBE Theme Editor is that it allows you to change the default colours so you can get results like this.

Be wary though, as the approach does make changes to the Visual Basic Editor Dynamic Linked Library file (VBE.DLL). Always, I mean always, make a backup before you change any system files. 

Conclusion

As you can see, changing the colours of the Visual Basic Editor is possible albeit limited.

Have you found any smarter ways to customise the look and feel of the Visual Basic Editor?

Let me know in the comments below.

Alternatively, would you care to share a screenshot of your Visual Basic Editor customisations?

Marcus

Marcus has been an Excel & VBA developer for over 20 years working in the trenches in Investment Banks and Assets Managers, previously in Melbourne and now in London.

  • bescot42 says:

    Thank you for this article, it was really useful!

    Just a minor note that in your colour theme you have listed Cyan (Pink). Cyan is light blue – I think you mean Magenta (Pink).

    • Marcus says:

      Hey bescot42,
      Thanks for dropping by.
      You’re absolutely right – I don’t know how I missed that.
      I’ve fixed that minor misdemeanor.
      All the best,
      Marcus

  • Fan says:

    Thanks a lot. It is really helpful for me.
    So kind are you!

  • Thanks!! Very very good!!

  • AL says:

    Hi, thank you,
    I would like to have my vba comment text (only) in Italic. Possible ?
    Thank you for your answer.
    AL

    • Marcus says:

      Hey AL,
      I can’t see any way that can be done, AL.
      While it is possible to change the colour of individual code sections (such as comments), the Font selection applies to *all* the VBA code.
      If you have a font that has a selectable italic style, that may work, but it would still apply to all your VBA code, not just the comments.

      The Visual Basic Editor (VBE) is quite antiquated compared to some modern IDEs. Unfortunately, even though VBA is still in wide demand, Microsoft won’t be upgrading the VBE.

      All the best,
      Marcus

      • AL says:

        Marcus,
        Thank you very much for your reply.
        I’ve seen some code with the comments in italics before (pdf), but also couldn’t reproduce it.
        I can’t send this example here. Shame.
        Anyway, thank you for answering me.
        Best regards.
        AL

        • Marcus says:

          Hey AL,
          Ahhhh, the plot thickens…

          Comments in italics in PDFs – yes I’ve seen that too.

          That would have been done with an external utility – not within the VBE itself.

          Some text editors are also able to do this. Notepad++ allows you define the formatting of a wide range of languages including making the comments italic (I just tested it!).

          I’ve also see web-based code formatters for making code (including VBA) “pretty”.

          But in the Visual Basic Editor itself? Nada 😐

          • AL says:

            Marcus,

            Ok, I understand better now.

            Thank you very much for your interest in my question, your speed of response and your research.
            It’s appreciated.

            Have a nice day.

            AL

  • Logan says:

    How do you put line numbers in your code as pictured?

    • Marcus says:

      Hey Logan,
      Thanks for dropping by. I’ve been using a VBA productivity add-in called MZTools for years.
      One of its features is automatically inserting line number in the code. This is invaluable for error logging. Combined with flagging module and procedure names, you can log and identify the source of errors down to the exact line number.
      You can find MZTools here:
      https://www.mztools.com/

      If you spend a lot of time in the VBE, MZTools wil save you a lot of time.

      All the best,
      Marcus

  • Ben says:

    Hello,
    Your guide was very helpful. I followed your color set to the letter. The only change I made was ‘Keyword Text’. I set it to purple instead of the light blue. I love the result. Thanks and keep up the good work.

  • >