1 1 1 1 1 1 1 1 1 1 Rating 0.00 (0 Votes)

Problemstellung:

Für 32Bit und 64Bit Office Versionen

Wie kann ich einen HEX-Farbwert in einen Long-Farbwert umrechnen?

Lösung:
Folgende Funktion in ein öffentliches Modul kopieren:

Public Function Hex2Long( _
     ByVal strHexColor As String) As Long
 
    Dim lngColor As Long
     Dim strR As String
     Dim strG As String
     Dim strB As String
 
    If Left(strHexColor, 1) = "#" Then
         strHexColor = Mid(strHexColor, 2)
     End If
 
    strHexColor = UCase(strHexColor)
 
    strR = Mid(strHexColor, 1, 2)
     strG = Mid(strHexColor, 3, 2)
     strB = Mid(strHexColor, 5, 2)
 
    lngColor = CLng("&H" & strB & strG & strR)
 
    Hex2Long = lngColor
 
End Function

Aufruf:

MsgBox Hex2Long("#FFFFFF")

Ergebnis:


 

Ähnliche Artikel