Mise en forme d'un commentaire via macro

Darnel

XLDnaute Impliqué
Bonjour,
grâce à l'aide de Tatiak et Pierre jean, j'ai le code suivant qui me crée un commentaire si la valeur de la Cellule B4 est la même que celle d'une des cellules de ma base de données
Ce que je voudrai c'est pouvoir mettre en forme ce commentaire. J'ai essayer comme ceci ( en rouge ce que j'ai ajouter) mais cela ne change rien.
Merci de votre aide
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
    If (Not Intersect(Range("B4"), Target) Is Nothing) And (Range("B4").Value <> "") Then
        ActiveSheet.Unprotect
        Range("B4").ClearComments
        For i = 1 To Sheets("Données").Range("C65536").End(xlUp).Row
            If Target.Value = Sheets("Données").Cells(i, 3).Value Then
                With Range("B4")
                ActiveSheet.Unprotect
                    On Error Resume Next
                    .AddComment
                    .Comment.Text Text:=.Comment.Text & _
                     "Il existe déjà un contrat n° " & .Value & " " & Chr(10)
                     [COLOR=red]With Selection.Font
                        .FontStyle = "Gras"
                        .Size = 10
                    End With
                    With Selection
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        .ReadingOrder = xlContext
                        .Orientation = xlHorizontal[/COLOR]
[COLOR=red]                    End With               
                       Selection.ShapeRange.Fill.ForeColor.SchemeColor = 51
                       Selection.ShapeRange.Line.Weight = 1.5
[/COLOR]                      .Comment.Visible = True
                End With
            End If
        Next i
    End If
ActiveSheet.Protect
End Sub
 

Hervé

XLDnaute Barbatruc
Re : Mise en forme d'un commentaire via macro

bonjour darnel :)

essaye comme ceci :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
    If (Not Intersect(Range("B4"), Target) Is Nothing) And (Range("B4").Value <> "") Then
        ActiveSheet.Unprotect
        Range("B4").ClearComments
        For i = 1 To Sheets("Données").Range("C65536").End(xlUp).Row
            If Target.Value = Sheets("Données").Cells(i, 3).Value Then
                With Range("B4")
                ActiveSheet.Unprotect
                    On Error Resume Next
                    .AddComment
                    .Comment.Text Text:=.Comment.Text & _
                     "Il existe déjà un contrat n° " & .Value & " " & Chr(10)
                     With .Comment.Shape.OLEFormat.Object
                        .ShapeRange.Fill.ForeColor.SchemeColor = 51
                        .Font.Size = 10
                        .FontStyle = "Gras"
                        .ShapeRange.Line.Weight = 1.5
                        .HorizontalAlignment = xlCenter
                        .VerticalAlignment = xlCenter
                        .ReadingOrder = xlContext
                        .Orientation = xlHorizontal
                     End With
                      .Comment.Visible = True
                End With
            End If
        Next i
    End If
ActiveSheet.Protect
End Sub
salut
 

Darnel

XLDnaute Impliqué
Re : Mise en forme d'un commentaire via macro

Bonjour Hervé

Merci de ta promptitude (mdr) à répondre à ma question et d'une manière si efficace.

Tout marche nickel Chrome comme d'aucuns diraient...:p

Merci et Bonne journée à toi
 

Discussions similaires

Réponses
0
Affichages
153
Réponses
7
Affichages
328

Statistiques des forums

Discussions
312 228
Messages
2 086 418
Membres
103 205
dernier inscrit
zch