This code takes the common dialog color, extracts the R, G, B values, and
converts each value to the correct HEX equivilant supported by HTML.
Original Author: Charlie Wilson
Inputs
Function requires a common dialog control color being selected and passed to the
function
Assumptions
You must add the common dialog control to your application. After the ShowOpen event
occurs, pass the color selected by the user to the function:
Dim sColHex as String
sColHex = HexRGB(cdlCont.color)
Returns
Function returns properly formatted HEX color value for HTML
API Declarations
None
Code
Private Function HexRGB(lCdlColor As Long)
Dim lCol As Long
Dim iRed, iGreen, iBlue As Integer
Dim vHexR, vHexG, vHexB As Variant
'Break out the R, G, B values from the common dialog color
lCol = lCdlColor
iRed = lCol Mod &H100
lCol = lCol &H100
iGreen = lCol Mod &H100
lCol = lCol &H100
iBlue = lCol Mod &H100
'Determine Red Hex
vHexR = Hex(iRed)
If Len(vHexR) < 2 Then
vHexR = "0" & vHexR
End If
'Determine Green Hex
vHexG = Hex(iGreen)
If Len(vHexG) < 2 Then
vHexG = "0" & iGreen
End If
'Determine Blue Hex
vHexB = Hex(iBlue)
If Len(vHexB) < 2 Then
vHexB = "0" & vHexB
End If
'Add it up, return the function value
HexRGB = "#" & vHexR & vHexG & vHexB
End Function