View Single Post
 
Old 11-24-2014, 04:15 AM
Hoggle42 Hoggle42 is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Nov 2014
Posts: 1
Hoggle42 is on a distinguished road
Default

As a companion to that function (very useful btw, thanks)

This one converts a VBA colour code to a six character hex code useable in CSS etc. Not sure if the blue and green are wrongly labelled, but the order is correct (it produces the right colour). The Hex function returns "0" rather than "00" so it needs padding.

Code:
Private Function fcnLongToHex(ByRef lngColor As Long) As String
    Dim hRed, hGreen, hBlue
    hRed = Hex(lngColor Mod 256)
    If Len(hRed) = 1 Then hRed = "0" & hRed
    hGreen = Hex((lngColor \ 256) Mod 256)
    If Len(hGreen) = 1 Then hGreen = "0" & hGreen
    hBlue = Hex((lngColor \ 256 \ 256) Mod 256)
    If Len(hBlue) = 1 Then hBlue = "0" & hBlue
    fcnLongToHex = hRed & hBlue & hGreen
End Function
Reply With Quote