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.
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.
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.
In the list of Code Colors, select ‘Normal Text’.
From the Foreground dropdown list, select ‘Yellow’.
From the Background dropdown list select ‘Black’.
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.
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?