1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Private Sub ChangeCouleur
'Application.EnableEvents = False
'Dim FCible As ThisComponent.getSheets, FSource As sheets, Lign As Integer
Dim Couleur, r, g, b As Integer
Dim oDoc as object
Dim oFeuilles as Object
Dim FCible As object ' com.sun.star.sheet.
Dim FSource As object 'com.sun.star.sheet.XSpreadsheet
Dim Plage as object
oDoc = ThisComponent
oFeuilles = oDoc.Sheets
'uneFeuille = lesFeuilles.getByName("Feuille1")
FCible =oFeuilles.getByName("Calques")
FSource = oFeuilles.getByName("CouleurRGB")
Lign = 2
Do While FCible.getCellByPosition(Lign, 1).getValue() <> ""
If FCible.getCellByPosition(Lign, 1).getValue()<>FCible.getCellByPosition(Lign, 2).getValue() Then
If InStr(Cells(Lign, 2), ",") = 0 Then
Couleur = FCible.Cells(Lign, 2).Value
If Couleur <= 0 Or Couleur > 255 Then Application.EnableEvents = True: Exit Sub
r = FSource.Cells(Couleur, 2)
g = FSource.Cells(Couleur, 3)
b = FSource.Cells(Couleur, 4)
FCible.Cells(Lign, 2).Interior.Color = RGB(r, g, b)
FCible.Cells(Lign, 3).Value = "&H" & Hex(FCible.Cells(Lign, 2).Interior.Color)
Else
chaine$ = Cells(Lign, 2)
r = Left(chaine$, InStr(chaine$, ",") - 1)
chaine$ = Right(chaine$, Len(chaine$) - InStr(chaine$, ",")):
g = Left(chaine$, InStr(chaine$, ",") - 1)
chaine$ = Right(chaine$, Len(chaine$) - InStr(chaine$, ",")):
b = chaine$
FCible.Cells(Lign, 2).Interior.Color = RGB(r, g, b)
End If
End If
Lign = Lign + 1
Loop
End Sub |
Partager