Autres Commentaire dans tous ces états

  • Initiateur de la discussion Initiateur de la discussion VIARD
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Bonjour à toutes et tous

J'ai repris légèrement le fichier pour améliorer.
Plus un fichier traitant uniquement, Cmt couleur.

Voici le code complet.


VB:
Sub Commentaire_Multi_Couleurs()
Dim cmt As Comment, i%
Dim txt(1 To 7) As String
Dim D(1 To 7) As Long
Dim F(1 To 7) As Long
Dim txt8$, Adr$
Dim R%, G%, B%
'----- c'est un essai laborieux en Excel2007

Adr = ActiveCell.Address
'----- Contrôle présence Adr & Adr2 -----
If Adr = "" Then
    MsgBox "adresse manquante"
    Exit Sub
End If
'-------- Cellules nommées Texte -------
'XXT1,XXT2,XXT3,XXT4,XXT5,XXT6,XXT7
'-------- Cellules nommées Couleurs ----
'Color1,Color2,Color3,Color4,Color5,Color6,Color7
'------- Choix Démo - Utilisateur ------
If Sheets("Feuil1").Range("A1") = 1 Then 'Démo
    txt(1) = "Frais établis ce jour: Période du:"
    txt(2) = " 5 Jan 2026"
    txt(3) = " au"
    txt(4) = " 24 Jan 2026"
    txt(5) = " Montant:"
    txt(6) = " 201.75"
    txt(7) = " €"
ElseIf Sheets("Feuil1").Range("A1") = 0 Then 'Utilisateur
    txt(1) = Range("XXT1").Text
    txt(2) = Chr(32) & Range("XXT2").Text
    txt(3) = Chr(32) & Range("XXT3").Text
    txt(4) = Chr(32) & Range("XXT4").Text
    txt(5) = Chr(32) & Range("XXT5").Text
    txt(6) = Chr(32) & Range("XXT6").Text
    txt(7) = Chr(32) & Range("XXT7").Text
ElseIf Sheets("Feuil1").Range("A1") = 2 Then 'Autre
    txt(1) = "Tableau:"
    txt(2) = Chr(32) & "Dimitri Ivanovitch"
    txt(3) = Chr(32) & "Mandeleïev"
    txt(4) = Chr(32) & "1869"
    txt(5) = Chr(32) & "né: 1834"
    txt(6) = Chr(32) & "décès: 1907"
    txt(7) = Chr(32) & ""
End If
'--- Texte final à traiter ---
    For i = 1 To 7
        txt8 = txt8 & txt(i)
    Next i
'--- Calcul de F (longueur fin de texte) ---
    For i = 1 To 7
        F(i) = Len(txt(i))
    Next i
'--- Calcul de D (début du texte) ---
    D(1) = 1
    For i = 2 To 7
        If i = 2 Then
            D(i) = D(i - 1) + Len(txt(i - 1)) + 1
        Else
            D(i) = D(i - 1) + Len(txt(i - 1))
        End If
    Next i
'----- Contrôle présence Commentaire -----
    With Range(Adr)
        If Not .Comment Is Nothing Then .Comment.Delete
        .AddComment txt8
        Set cmt = .Comment
        cmt.Visible = False
    End With
'------------ Couleurs + gras ------------
With cmt.Shape.TextFrame
    .Characters(D(1), F(1)).Font.ColorIndex = Range("Color1").Value  'txt1
    .Characters(D(1), F(1)).Font.Bold = True
    .Characters(D(2), F(2)).Font.ColorIndex = Range("Color2").Value  'txt2
    .Characters(D(2), F(2)).Font.Bold = True
    .Characters(D(3), F(3)).Font.ColorIndex = Range("Color3").Value  'txt3
    .Characters(D(3), F(3)).Font.Bold = True
    .Characters(D(4), F(4)).Font.ColorIndex = Range("Color4").Value  'txt4
    .Characters(D(4), F(4)).Font.Bold = True
    .Characters(D(5), F(5)).Font.ColorIndex = Range("Color5").Value  'txt5
    .Characters(D(5), F(5)).Font.Bold = True
    .Characters(D(6), F(6)).Font.ColorIndex = Range("Color6").Value  'txt6
    .Characters(D(6), F(6)).Font.Bold = True
    .Characters(D(7), F(7)).Font.ColorIndex = Range("Color7").Value  'txt7
    .Characters(D(7), F(7)).Font.Bold = True
End With
'---------- Police ----------
    cmt.Shape.TextFrame.Characters.Font.Italic = True
    cmt.Shape.TextFrame.Characters.Font.Size = 20
'---------- épaisseur bordure ----------
    cmt.Shape.Line.Weight = 1.5
'---------- Couleur Bordure ----------
    cmt.Shape.Line.ForeColor.RGB = RGB(255, 0, 0)
'---------- Type ----------
    cmt.Shape.AutoShapeType = msoShapeHorizontalScroll 'msoShapeVerticalScroll 'msoShapeHorizontalScroll 'msoShapeRoundedRectangle
'---------- Fond du commentaire ----------
With Sheets("Feuil1")
    R = .Range("C2").Value
    G = .Range("C3").Value
    B = .Range("C4").Value
End With
With cmt.Shape.Fill
    .ForeColor.RGB = RGB(R, G, B)
    .Solid
End With
'---------- Ajustement automatique ----------
    cmt.Shape.TextFrame.AutoSize = True
ActiveCell.Comment.Visible=True
End Sub
'=================================

Salutation
Jean-Paul
Cmt_Couleur.JPG
Cmt_Couleur_2.JPG
 

Pièces jointes

Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
0
Affichages
175
Réponses
16
Affichages
347
Réponses
4
Affichages
489
Réponses
2
Affichages
393
Réponses
40
Affichages
2 K
Retour