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 Long-Farbwert  in einen HEX-Farbwert umrechnen?

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

Public Type tRGB
     bytR As Byte
     bytG As Byte
     bytB As Byte
 End Type
 
Public Function Long2Hex( _
     ByVal lngRGBColor As Long) As String
 
    Dim tmpCol As tRGB
     Dim strR As String
     Dim strG As String
     Dim strB As String
 
    With tmpCol
         .bytR = lngRGBColor Mod 256
         .bytG = (lngRGBColor \ 256) Mod 256
         .bytB = lngRGBColor \ 65536
     End With
 
    strR = Trim(Hex(tmpCol.bytR))
     strG = Trim(Hex(tmpCol.bytG))
     strB = Trim(Hex(tmpCol.bytB))
 
    If Len(strR) = 1 Then strR = "0" & strR
     If Len(strG) = 1 Then strG = "0" & strG
     If Len(strB) = 1 Then strB = "0" & strB
 
    Long2Hex = "#" & strR & strG & strB
 
End Function

Aufruf:

MsgBox Long2Hex(12632256)

Ergebnis:


 

Ähnliche Artikel