How Can I Get The Web Hex Color Of Something Like Textbox Foreground Like:
MyHexColor = Text1.Forground
And Produce Something Like: #FF0000 For Red?
Printable View
How Can I Get The Web Hex Color Of Something Like Textbox Foreground Like:
MyHexColor = Text1.Forground
And Produce Something Like: #FF0000 For Red?
Something like this should work...
Code:Dim myHexValue As String
myHexValue = Hex(RGB(255, 0, 0))
myHexValue = myHexValue & String(6 - Len(myHexValue), "0")
myHexValue = "#" & myHexValue
Debug.Print myHexValue
Youngbuck's code has errors in it. He added the zeropadding to the wrong side, etc.
a sub i wrote contains this function among others. It is attached. But basically, if you want webcolor, convert the long color value to hex and switch the two letters on the right with the two on the left
dim longcol as long
dim hexcol as string
longcol = text1.textcolor (or whatever)
hexcol = hex$(longcol)
hexcol = right$("000000"+hexcol, 6)
hexcol = right$(hexcol, 2)+mid$(hexcol, 3, 2)+left$(hexcol, 2)
msgbox hexcol
The swap is cuz vb is backwards to web.