Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|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

4 Answers

up vote 9 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.

share|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

TeX HeX is spot on. However, it IS possible to change the 16 built-in colors with your own. It just requires a bit of hex editing. Here's a step-by-step guide. (Note: This is for VB6 SP6, file version 6.0.97.82).

  1. Backup your VB6.EXE file in your VB98 program folder. (Optional, but recommended).

  2. Fire up your favorite hex editor (shout out to HxD) and open VB6.EXE.

  3. Jump to address 0xE22F4. This is the start of the color table.

You should see four zeros. This represents the color black in RRGGBBAA format (alpha isn't supported so it's really just RRGGBB00 format). The next four bytes specify the next color and so on until you get to FFFFFF00 (white) ending at offset 0xE2333.

  1. Edit any of these four-byte values to your choosing. Just use the appropriate hex values in RGB format, followed by a zero byte. For example, RGB(64, 128, 192) would be 40 80 C0 00.

  2. Save your changes to the EXE and fire up VB6. You should see your new color(s) in the slots previously occupied by the built-in VB colors.

share|improve this answer
Hmm, I searched with the tool everything on a system with office 2003 and it doesn't find any file named VB6.exe or a folder VB98. Is this answer only for Office 2007 like the OP has? However the version 6.0.97.82 is older than mine with Office 2003. – nixda Feb 6 at 19:49
1  
@nixda Nothing on my system either - I think Bond is referring to the VB6 application on his system, not the VBA integrated into Excel. I'm going to have a look through the Excel executable and some of the VBA DLLs, and see if I can find any colour tables. – Breakthrough Feb 6 at 21:05
Sorry, yes, I am referring to the VB6 IDE. I was searching for a solution to VB6 when I stumbled across this thread. Both VB6 and VBA use the CodeForeColors and CodeBackColors strings. VB6 stores these strings at a slightly different location (HKEY_CURRENT_USER\Software\Microsoft\VBA\Microsoft Visual Basic) but the method is similar to VBA, so I'm sure you could do something similar there. If I get a chance, I'll try to do the same for VBA. – Bond Feb 6 at 21:44
I found a VBE6.DLL in C:\Program Files (x86)\Common Files\microsoft shared\VBA\VBA6, but I don't see any apparent colour tables, even after disassembling the file. There's a few other related files that might be worth looking at, I haven't looked in the Excel binary itself yet either. – Breakthrough Feb 6 at 21:49
I have Office 2010 on my PC so I have VBE7.DLL, not VBE6.DLL, but it should be the same process. The colors are the same. If you look at the colors in the order they're displayed, they should be: Black = 00 00 00 00 Navy = 00 00 80 00 Green = 00 80 00 00 Turqoise = 00 80 80 00 Magenta = 80 00 00 00 Violet = 80 00 80 00 Olive = 80 80 00 00 Lgt Grey = C0 C0 C0 00 Drk Grey = 80 80 80 00 ... I've added the hex color codes next to each. So just open VBE6.DLL in a hex editor and search for the following hex string: – Bond Feb 12 at 16:13
show 1 more comment

Bond's solution (editing the color table in VB6.exe) works perfectly for modifying the color table in the VB6 IDE.

However, I found that when a modified color is selected and VB6 is shut down, VB6 is not able to properly save the modified color to the registry.

Normally, VB6 will write an index into the 16-value color table for each text item that can have its color modified.

The color indices are written to the registry here:

HKEY_CURRENT_USER\Software\Microsoft\VBA\Microsoft Visual Basic\CodeForeColors HKEY_CURRENT_USER\Software\Microsoft\VBA\Microsoft Visual Basic\CodeBackColors

For example, the CodeForeColors value will look something like this: 6 14 5 0 1 3 13 4 15 0 0 0 0 0 0 0

Values from 1 to 16 represent a color in the color table and 0 means 'Auto'.

BUT, when a modified color is selected, VB6 will write a number outside of the index range to the registry and the CodeForeColors value will look something like this:

5245006 14 5 0 1 3 13 4 15 0 0 0 0 0 0 0

The next time VB6 is started it will not be able to set the correct color for the item that had been set to the modified color.

I'm still trying to figure out a solution but wanted to post what I've found so far.

share|improve this answer

record a macro in Word and change the color of the text from palette, when you view that macro you will see he code like 12611584

OR

try

.Color = RGB(255, 255, 255)

Warning: this code is not tested

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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