VB and VBA Users Source Code: Converting a VB color to an HTML code code
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Converting a VB color to an HTML code code
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, June 13, 2002
Hits:
750
Category:
Internet/Remote Comms
Article:
The following code converts a VB color to an HTML color code. Option Explicit Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long 'Purpose : Convert a VB color into HTML color code 'Inputs : lColour The VB color to convert 'Outputs : Returns a string representing the HTML color code 'Author : Andrew Baker 'Date : 13/June/2002 'Notes : 'Revisions : Function HTMLColor(ByVal lColour As Long) As String Dim sResult As String 'Convert color to hex sResult = Hex(lColour) If left$(sResult, 1) = "8" Then 'Convert system colors lColour = Val("&H" & Mid$(sResult, 2)) lColour = GetSysColor(lColour) sResult = Hex(lColour) End If sResult = String(6 - Len(sResult), "0") & sResult HTMLColor = """#" & Right$(sResult, 2) & Mid$(sResult, 3, 2) & Left$(sResult, 2) & """" End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder