M
Matthew Herbert
All,
Direct Question: Is it possible to get the Long result of RGB from a string
expression (reference Evalute) using built-in VBA functionality?
The code below (comments included) illustrates that the SIN function works
properly with Evaluate, but the RGB function does not. (See VBE help for
more details on the Evaluate method). I believe that RGB does not work
because, as far as I can tell, RGB is a VBA function and not a worksheet
function. (Also, as far as I can tell, SIN is both a VBA and worksheet
function).
So, is it possible to get the Long result of RGB from a string expression
using built-in VBA functionality? (If I need to build a custom function to
do this for me, then that is not a problem because I can write the syntax,
and because I'm sure there is code out there for converting the RGB integer
values to a Long. I simply want to see if there is built-in functionality
that would prevent me from having to create a custom function to achieve the
same result).
Thanks,
Matthew Herbert
Sub EvaluateStringQuestion()
Dim strSin As String
Dim dblSin As Double
Dim strRgb As String
Dim lngRGB As Long
Dim varRgb As Variant
'----------------------------------------------------------
'SIN Related (Shown to prove Evaluate does work)
strSin = "SIN(45)"
'The following is 0.850903524534118:
dblSin = Application.Evaluate(strSin)
'----------------------------------------------------------
'----------------------------------------------------------
'RGB Related (Doesn't seem to work)
strRgb = "RGB(242, 242, 242)"
'The following is 15921906 (which is what I expect
' from varRgb):
lngRGB = RGB(242, 242, 242)
'The following returns "Error 2029", hence the Variant
' data type:
varRgb = Application.Evaluate(strRgb)
'The following do not work:
' lngRGB = Application.Evaluate(strRgb)
' lngRGB = Application.Evaluate("RGB(242, 242, 242)")
'----------------------------------------------------------
End Sub
Direct Question: Is it possible to get the Long result of RGB from a string
expression (reference Evalute) using built-in VBA functionality?
The code below (comments included) illustrates that the SIN function works
properly with Evaluate, but the RGB function does not. (See VBE help for
more details on the Evaluate method). I believe that RGB does not work
because, as far as I can tell, RGB is a VBA function and not a worksheet
function. (Also, as far as I can tell, SIN is both a VBA and worksheet
function).
So, is it possible to get the Long result of RGB from a string expression
using built-in VBA functionality? (If I need to build a custom function to
do this for me, then that is not a problem because I can write the syntax,
and because I'm sure there is code out there for converting the RGB integer
values to a Long. I simply want to see if there is built-in functionality
that would prevent me from having to create a custom function to achieve the
same result).
Thanks,
Matthew Herbert
Sub EvaluateStringQuestion()
Dim strSin As String
Dim dblSin As Double
Dim strRgb As String
Dim lngRGB As Long
Dim varRgb As Variant
'----------------------------------------------------------
'SIN Related (Shown to prove Evaluate does work)
strSin = "SIN(45)"
'The following is 0.850903524534118:
dblSin = Application.Evaluate(strSin)
'----------------------------------------------------------
'----------------------------------------------------------
'RGB Related (Doesn't seem to work)
strRgb = "RGB(242, 242, 242)"
'The following is 15921906 (which is what I expect
' from varRgb):
lngRGB = RGB(242, 242, 242)
'The following returns "Error 2029", hence the Variant
' data type:
varRgb = Application.Evaluate(strRgb)
'The following do not work:
' lngRGB = Application.Evaluate(strRgb)
' lngRGB = Application.Evaluate("RGB(242, 242, 242)")
'----------------------------------------------------------
End Sub