[RESOLU] Modification fichier M. Jacques Boisgontier - Commentaires dynamiques VBA

Spinzi

XLDnaute Impliqué
Bonjour à tous,

je cherchais une solution de manière à lier un commentaire à une cellule excel (http://boisgontierjacques.free.fr/fichiers/Commentaires/AfficheCmt.xls)

J'ai trouvé mon bonheur mais j'ai un petit souci de mise en forme : le commentaire se "rafraichit" et la taille du commentaire revient à l'origine (trop petite).
L'autosize ne me convient pas non plus car mes commentaires sont souvent importants en nombre de caractères.

Il faudrait, si c'est possible, que la taille des commentaires soit modifiable de manière identique au standard Excel (c'est à dire que la mise à jour de la taille du commentaire ne se fasse pas).

Ci dessous le code :
Code:
Function AfficheCmt(cel, cond, msg, coul)
   Application.Volatile
   Set f = Sheets(Application.Caller.Parent.Name)
   If Not cel.Comment Is Nothing Then cel.Comment.Delete
   If cond Then
     With cel
       If .Comment Is Nothing Then .AddComment
       .Comment.Shape.Width = Len(msg) * 7
       .Comment.Shape.Height = 12
       .Comment.Shape.Left = .Left + .Width + 5
       .Comment.Shape.Top = .Top - 2
       .Comment.Visible = True
        tmp = CStr(msg)
       .Comment.Text Text:=tmp
       .Comment.Shape.Fill.ForeColor.SchemeColor = coul
       .Comment.Visible = False
      End With
    End If
    AfficheCmt = ""
 End Function

Un exemple est trouvable sur le site.

Si mon besoin n'est pas clair, n'hésitez pas à me demander plus amples explications !

Spinzi
 
Dernière édition:

Spinzi

XLDnaute Impliqué
Re : Modification fichier M. Jacques Boisgontier - Commentaires dynamiques VBA

Bonjour,

@Gosselien : parce que le fichier est disponible directement sur la page de M. Boisgontier ? Et peut être aussi parce que justement dès que je réouvre le fichier ma modification s'est effacée ? ..........

@Chris : la manip ne fonctionne pas. J'ai essayé en supprimant les marges droite et gauche mais rien n'y fait.

PS : comme apparemment certains ont du mal à cliquer sur le lien, vous trouverez en PJ le même fichier avec un peu plus de texte pour vérifier le test.
 

Pièces jointes

  • Lier commentaire cellule XL.xlsm
    20.4 KB · Affichages: 38
Dernière édition:

gosselien

XLDnaute Barbatruc
Re : Modification fichier M. Jacques Boisgontier - Commentaires dynamiques VBA

Bonjour,

sauf erreur, :)
on mémorise les dimensions avant d'effacer le commentaire :)

Code:
Function AfficheCmt(cel, cond, msg, coul)
Application.Volatile
Dim mWidth, mHeight
Set f = Sheets(Application.Caller.Parent.Name)
If Not cel.Comment Is Nothing Then
  mWidth = cel.Comment.Shape.Width ' mémoriser les dimensions
  mHeight = cel.Comment.Shape.Height
  cel.Comment.Delete
  If cond Then
    With cel
      If .Comment Is Nothing Then .AddComment
      .Comment.Shape.Width = mWidth ' restaurer les comments
      .Comment.Shape.Height = mHeight
      .Comment.Shape.Left = .Left + .Width + 5
      .Comment.Shape.Top = .Top - 2
      .Comment.Visible = True
      tmp = CStr(msg)
      .Comment.Text Text:=tmp
      .Comment.Shape.Fill.ForeColor.SchemeColor = coul
      .Comment.Visible = False
    End With
  End If
End If
AfficheCmt = ""
End Function

P.
 

Statistiques des forums

Discussions
312 203
Messages
2 086 181
Membres
103 152
dernier inscrit
Karibu