How return built-in constant value from its name

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,915
Cell A1 contains the string: rgbAliceBlue

rgbAliceBlue is a built-in VBA constant with the numeric value of 16775408

In the VBE Immediate window if I enter ?rgbAliceBlue it shows the value: 16775408

Application.Evaluate("rgbAliceBlue") returns Error 2029 - Type mismatch

How can I extract the numeric value of a built-in excel constant using the name of a built-in excel constant?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
How about
Code:
val(rgbAliceBlue)
 
Upvote 0
val(rgbAliceBlue) does return the numeric value, but when I retrieve the value of a text string in Range("A1") it is processed as a string and Val("rgbAliceBlue") returns 0

I want to retrieve the name of a color from A1

A1 = rgbAliceBlue

which is a text value

In code
x = Range("A1") .Value
or
x = Range("A1") .Value2
or
x = Range("A1") .Text

all result in x having the value of "rgbAliceBlue" (a string)

and Val(X) returns 0, not 16775408 (the value of the constant: rgbAliceBlue)

Is there a function (or code) that will return the numeric value of a built-in constant using its name as input?
 
Upvote 0
I missed the part about it being in A1.
And have no idea how to convert a string to a constant
 
Upvote 0
I am pretty sure you cannot retrieve the value directly as, to my understanding, all constants are replaced by their value at the time the code is compiled (which is before the code itself physically executes), so the running VB code has no knowledge that a constant name was used originally and, hence, does not know that rgbAliceBlue is the name of a constant nor that it has an associated value.
 
Upvote 0
Thank you both for your suggestions and comments.

I had thought there might be some way to use the functionality of the immediate window since it returns numeric values when evaluating the built-in constants.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top