I'm working on a few projects for work using Excel and VBA, so I have no choice but to use the Microsoft Visual Basic editor. I normally wouldn't mind, but I can't figure out how to set a custom colour for the editor (I can only choose from the default palette).

To change the colour currently, I go to Tools -> Options -> Editor Format... However, your choices are only limited to the default (and basic) 16 colours - and when I say basic, I mean basic, like pink, blue, black, white, etc...

Does anyone know how to either specify a custom colour, or at the very least, change some of the colours that show up in the default palette?

link|improve this question

I looked around again, as someone had asked a similar question either on here or SO, but I couldn't dig it up. In that general arena, there is MZ-Tools which seems to have everything but the kitchen sink, except for highlighting. People seem to claim they use Notepad++, and I found a VB specific highlighting mode for that, but I don't know if that will suffice for VBA. – jonsca Jul 21 '11 at 19:43
@jonsca, that's what I've been using for the time being - it's just a pain because of the lack of auto-complete (for my functions/variables and the built-in Excel objects), and the fact that I'm constantly copying and pasting between editors. I'm open to using VBA addons, but I have tried MZ-Tools and it does not have custom syntax highlighting. :( – Breakthrough Jul 21 '11 at 19:45
Yeah, it seems to be a vexing problem for a lot of people. Wish I had had something better to report. – jonsca Jul 21 '11 at 21:42
feedback

1 Answer

up vote 8 down vote accepted
+50

I think you can withdraw the bounty, as this is not possible.

VBA reads the settings for the colors from these registry keys:

HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0\Common\CodeForeColors HKEY_CURRENT_USER\Software\Microsoft\VBA\6.0\Common\CodeBackColors

Each of these keys contains a list of values (separated by space) for each entry inside Tools -> Options -> Editor Format. For example, the first value inside CodeBackColors is the background color and the first value inside CodeForeColors is the foreground color for normal text. The values are the internal id for the color, 0 means AUTO coloring, 11 shows cyan, 5 red etc.

To give it a try: Close Excel, change the first value of CodeBackColors to 5 and restart Excel. The background of the code editor will now be red.

The problem is that the VBA Editor does only support these internal values and the highest number it understands is 16. Any other value will not be accepted and it defaults back to AUTO.

I have tried several options of entering different values (e.g. 128255128, 16777215, #aaffee, 255 or "170,255,238") and none of them worked.

Therefore I think it is technically not possible to assign other colors.

link|improve this answer
Thanks for the answer. IIRC, you can't withdraw a bounty, but if you literally cannot do this, then I shall award it to you for the most correct answer. I want to wait a bit more to see if any more answers are posted, but thanks for your response, +1. – Breakthrough Jul 27 '11 at 10:29
I have to admit, that sounds even better :) – TeX HeX Jul 27 '11 at 10:42
"Total Visual CodeTools" (fmsinc.com/vb6/CodingTools.html) from FMS has a tool "VBE Color Scheme manager to easily see and set colors for your editor". If you download the user manual (a PDF) it shows screenshots that while making it easier to set colors is still limited to a 16 color palette. Would think if there was a direct way to use custom colors they would have included it in this tool. Looks like Tex Hex is correct. – Brian Aug 1 '11 at 14:25
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.