Function getRGB1(rcell) As String
Dim sColor As String
sColor = Right("000000" & Hex(rcell.Interior.Color), 6)
getRGB1 = Right(sColor, 2) & Mid(sColor, 3, 2) & Left(sColor, 2)
End Function
'source: Allen Wyatt
Sub Test()
MsgBox CouleursRGB(ActiveCell)
End Sub
A partir des composantes RGB de la celluleDonc si quelqu'un trouve comment traduire un code couleur excel (ActiveCell.Interior.Color) ou code couleur RGB en code couleur excel hexadécimal (ceux utilisés dans les userform (ex : PFF000010&), ça m’intéresse
Re
Voici une macro pour tester la fonction
VB:Sub Test() MsgBox CouleursRGB(ActiveCell) End Sub
Sub Test()
MsgBox getRGB1(ActiveCell)
End Sub
Sub Couleurs_XL()
Dim i&, str0$, str$
With Cells(1, 1).Resize(, 7)
.Value = Array("FOND", "POLICE", "HTML", "ROUGE", "VERT", "BLEU", "COULEUR")
.Font.Bold = True
End With
For i = 0 To 56
Cells(i + 2, 1).Interior.ColorIndex = i: Cells(i + 2, 2).Font.ColorIndex = i: Cells(i + 2, 2) = "[Couleur:" & i & "]"
str0 = Right("000000" & Hex(Cells(i + 2, 1).Interior.Color), 6)
str = Right(str0, 2) & Mid(str0, 3, 2) & Left(str0, 2)
Cells(i + 2, 3) = "#" & str
Cells(i + 2, 4) = "=Hex2dec(""" & Right(str0, 2) & """)"
Cells(i + 2, 5) = "=Hex2dec(""" & Mid(str0, 3, 2) & """)"
Cells(i + 2, 6) = "=Hex2dec(""" & Left(str0, 2) & """)"
Cells(i + 2, 7) = "[Couleur:" & i & "]"
Next i
With [A1].CurrentRegion
.Borders.LineStyle = 1: .HorizontalAlignment = xlCenter
End With
End Sub
'adapté de colors56 - databison
J'essaye avec le 1er code de staple (le 2nd me fait peur)
Public Function getRGB1(rcell) As String
Dim sColor As String
sColor = Right("000000" & Hex(rcell.Interior.Color), 6)
getRGB1 = Right(sColor, 2) & Mid(sColor, 3, 2) & Left(sColor, 2)
End Function
Sub a_test() 'raccourcis ctrl+m
'Convertir les codes couleurs en valeurs RGB
Dim RGBC, Blue, Green, Red As Long
RGBC = ActiveCell.Interior.Color
Red = Int(RGBC Mod 256)
Green = Int((RGBC Mod 65536) / 256)
Blue = Int(RGBC / 65536)
MsgBox "Hexa : " & getRGB1(ActiveCell) & Chr(10) & Chr(10) & _
"Excel Color :" & RGBC & Chr(10) & Chr(10) & _
"RED (rouge): " & Red & vbCr & vbCr & _
"GREEN (vert): " & Green & vbCr & vbCr & _
"BLUE (bleu): " & Blue, , " RGB Values"
End Sub
Non je parlais bien de ton 2nd codeRe
Tu parles de mon second code ou du classeur posté par Modeste geedee?
Tu peux lancer la macro Couleurs_XL sans souci, en l’exécutant sur une feuille vierge.