DavidWHouse
New Member
- Joined
- Jan 18, 2016
- Messages
- 6
Dear friends,
First post. Sorry for any mistakes in netiquette, etc.
I am trying to work on the programmatic creation of objects that have foreground and background colors. The value of the dot referenced (and other) properties is stored in a worksheet and retrieved. Setting RGB values of .forecolor et al when these are stored as strings such as "RGB(200, 150, 125)" gives very odd results, in the sense that when Evaluate is called once with such a string, it offers one [incorrect] result, and if called a second time with the same syntax it gives a second [correct] result, which thereafter does not vary.
Thus:
Any ideas about why this happens, and (if I've made some mistake in code), what to do to correct it?
d.
First post. Sorry for any mistakes in netiquette, etc.
I am trying to work on the programmatic creation of objects that have foreground and background colors. The value of the dot referenced (and other) properties is stored in a worksheet and retrieved. Setting RGB values of .forecolor et al when these are stored as strings such as "RGB(200, 150, 125)" gives very odd results, in the sense that when Evaluate is called once with such a string, it offers one [incorrect] result, and if called a second time with the same syntax it gives a second [correct] result, which thereafter does not vary.
Thus:
Code:
Sub tstEvalRGBString()
Dim shtActive As Excel.Worksheet
Dim shpTest As Shape
'
'
Set shtActive = ActiveWorkbook.ActiveSheet
Set shpTest = shtActive.Shapes.AddShape(Type:=msoShapeRectangle, Left:=1, Top:=1, Width:=100, Height:=100)
'
With shpTest.Fill.ForeColor
Evaluate (".RGB = RGB(200, 150, 125)")
Debug.Print .RGB & " from Eval" ' prints "13998939 from Eval" on my system
.RGB = RGB(200, 150, 125)
Debug.Print .RGB & " direct" ' prints "8230600 direct" on my system
Evaluate (".RGB = RGB(200, 150, 125)")
Debug.Print .RGB & " from Eval #2" ' prints "8230600 from Eval #2" on my system
Evaluate (".RGB = RGB(200, 150, 125)")
Debug.Print .RGB & " from Eval #3" ' prints "8230600 from Eval #2" on my system
End With
End Sub
Any ideas about why this happens, and (if I've made some mistake in code), what to do to correct it?
d.