AW: VBA-BackColor-Farbwert in RGB Farbwert wandeln?
27.07.2011 09:54:35
Tino
Hallo,
versuch mal so.
kommt als Code in UserForm1
Option Explicit
Private Sub CommandButton1_Click()
Dim nR, nG, nB
Farbe_RGB Me.BackColor, nR, nG, nB
Range("A1").Interior.Color = RGB(nR, nG, nB)
End Sub
kommt als Code in Modul1
Option Explicit
Sub Farbe_RGB(ByVal BackColorWert, nR, nG, nB)
Dim R, G, B
R = Hex(BackColorWert - (BackColorWert \ 65536) * 65536 - _
((BackColorWert - (BackColorWert \ 65536) * 65536) \ 256) * 256)
G = Hex((BackColorWert - (BackColorWert \ 65536) * 65536) \ 256)
B = Hex(BackColorWert \ 65536)
If Len(R) < 2 Then R = R & "0"
If Len(G) < 2 Then G = G & "0"
If Len(B) < 2 Then B = B & "0"
nR = CDec("&H" & R)
nG = CDec("&H" & G)
nB = CDec("&H" & B)
End Sub
Gruß Tino