How return built-in constant value from its name

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,910
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,213,536
Messages
6,114,202
Members
448,554
Latest member
Gleisner2

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