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 !
l'objectif est de pouvoir dimensionner la case du commentaire prêt à être saisi. et d'afficher une case vierge pour commentaire...
et qu'il n'apparaisse qu'au survol.
pourtant ici, il apparaît le dernier toujours ouvert, or ce n'est pas l'objectif...
Comment faire pour que le fond du commentaire soit blanc par défaut et non jaunâtre ?
voici le code:
VB:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' Applique aux colonnes B, C, D (2, 3, 4)
If Target.Column >= 2 And Target.Column <= 4 Then
Cancel = True ' Annule le menu contextuel
' Configuration de l'affichage des commentaires
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
' Crée un nouveau commentaire si nécessaire
If Target.Comment Is Nothing Then
Target.AddComment Text:="" ' Crée un commentaire vide
End If
' Rend le commentaire visible et éditable
Target.Comment.Visible = True
Target.Comment.Shape.Select ' Active l'édition immédiate
End If
If Target.Comment Is Nothing Then
Target.AddComment Text:=""
' Ne pas mettre Target.Comment.Visible = True
End If
' Ne pas forcer l'affichage du commentaire
End Sub
Et un bonus si tu souhaites changer la couleur du texte du com (j'utilise actuellement sur mon calendrier)
je n'ai pas activé mais si tu souhaites
Code:
Option Explicit
Private lastCmt As Comment
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Const FIRST_COL As Long = 2
Const LAST_COL As Long = 4
If Target.Column < FIRST_COL Or Target.Column > LAST_COL Then Exit Sub
Cancel = True
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
If Not lastCmt Is Nothing Then
If Not lastCmt Is Target.Comment Then lastCmt.Visible = False
Set lastCmt = Nothing
End If
Dim cmt As Comment 'ou As Object si AddComment2
If Target.Comment...
Option Explicit
Private lastCmt As Comment
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 2 Or Target.Column > 4 Then Exit Sub
Cancel = True
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
If Not lastCmt Is Nothing Then
lastCmt.Visible = False
Set lastCmt = Nothing
End If
If Target.Comment Is Nothing Then
Target.AddComment "" 'sinon AddComment2 pour Office 365
With Target.Comment.Shape
.Width = 180
.Height = 60
.Fill.ForeColor.RGB = vbWhite
' .Line.Visible = msoFalse
End With
End If
With Target.Comment
.Visible = True
.Shape.Select
End With
Set lastCmt = Target.Comment
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not lastCmt Is Nothing Then
lastCmt.Visible = False
Set lastCmt = Nothing
End If
End Sub
Bonjour
comment transforme t on les commentaire en postit auto hidden
comme ceci:
VB:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' Applique aux colonnes B, C, D (2, 3, 4)
If Target.Column >= 2 And Target.Column <= 4 And Target.Count = 1 Then
Cancel = True ' Annule le menu contextuel
' Configuration de l'affichage des commentaires
Application.DisplayCommentIndicator = False 'il ne s'affiche pas au survol
' Crée un nouveau commentaire si nécessaire
If Target.Comment Is Nothing Then
Target.AddComment Text:="" ' Crée un commentaire vide
End If
' Rend le commentaire visible et éditable
On Error Resume Next
With Target.Comment
.Visible = True 'on le met visible d'office (pas besoins du survol)
With .Shape
.Width = 200 'on dimensionne le width
.Height = 150 'on dimensionne le height
.Select ' Active l'édition immédiate
End With
End With
DoEvents 'ON LAISSE LES EXECUSSIONs AUTRES SE FAIRE UN PEU
Application.SendKeys " +{Backspace}" 'on tape un espace et un retour en arriere pour que le caret cligonant d'edition soit au debut
Application.SendKeys "" ' réactive le pavé numérique si besoin
End If
' Ne pas forcer l'affichage du commentaire
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each c In ActiveSheet.Comments
c.Visible = False
Next
End Sub
au clickdroit le commentaire est créé (si il n'existe pas) et affiché de force
il est dimensionné
et placer en mode edition immédiatement le curseur clignote
la sélection dans une autre cellule masque les commentaires affichés donc on peut considérer que ca fait office de retractation du commentaire
important le triangle non visible !!! ca bloque l'affichage au survol
terminé
Option Explicit
Private lastCmt As Comment
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column < 2 Or Target.Column > 4 Then Exit Sub
Cancel = True
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
If Not lastCmt Is Nothing Then
lastCmt.Visible = False
Set lastCmt = Nothing
End If
If Target.Comment Is Nothing Then
Target.AddComment "" 'sinon AddComment2 pour Office 365
With Target.Comment.Shape
.Width = 180
.Height = 60
.Fill.ForeColor.RGB = vbWhite
' .Line.Visible = msoFalse
End With
End If
With Target.Comment
.Visible = True
.Shape.Select
End With
Set lastCmt = Target.Comment
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not lastCmt Is Nothing Then
lastCmt.Visible = False
Set lastCmt = Nothing
End If
End Sub
@Nicolas JACQUIN
Attention le select ne suffit pas a le mettre en mode édition
mais l'idée de la variable globale pour le hold comm c'est pas mal du tout
Bonjour
comment transforme t on les commentaire en postit auto hidden
comme ceci:
VB:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' Applique aux colonnes B, C, D (2, 3, 4)
If Target.Column >= 2 And Target.Column <= 4 And Target.Count = 1 Then
Cancel = True ' Annule le menu contextuel
' Configuration de l'affichage des commentaires
Application.DisplayCommentIndicator = False 'il ne s'affiche pas au survol
' Crée un nouveau commentaire si nécessaire
If Target.Comment Is Nothing Then
Target.AddComment Text:="" ' Crée un commentaire vide
End If
' Rend le commentaire visible et éditable
On Error Resume Next
With Target.Comment
.Visible = True 'on le met visible d'office (pas besoins du survol)
With .Shape
.Width = 200 'on dimensionne le width
.Height = 150 'on dimensionne le height
.Select ' Active l'édition immédiate
End With
End With
DoEvents 'ON LAISSE LES EXECUSSIONs AUTRES SE FAIRE UN PEU
Application.SendKeys " +{Backspace}" 'on tape un espace et un retour en arriere pour que le caret cligonant d'edition soit au debut
Application.SendKeys "" ' réactive le pavé numérique si besoin
End If
' Ne pas forcer l'affichage du commentaire
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each c In ActiveSheet.Comments
c.Visible = False
Next
End Sub
au clickdroit le commentaire est créé (si il n'existe pas) et affiché de force
il est dimensionné
et placer en mode edition immédiatement le curseur clignote
la sélection dans une autre cellule masque les commentaires affichés donc on peut considérer que ca fait office de retractation du commentaire
important le triangle non visible !!! ca bloque l'affichage au survol
terminé
Voici la version corrigée en espérant que ce soit bon et bien expliqué.
VB:
Option Explicit
Private lastCmt As Comment
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Const FIRST_COL As Long = 2
Const LAST_COL As Long = 4
If Target.Column < FIRST_COL Or Target.Column > LAST_COL Then Exit Sub
Cancel = True
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
If Not lastCmt Is Nothing Then
If Not lastCmt Is Target.Comment Then lastCmt.Visible = False
Set lastCmt = Nothing
End If
Dim cmt As Comment 'ou As Object si AddComment2
If Target.Comment Is Nothing Then
Set cmt = Target.AddComment("") 'AddComment2 pour Office 365 « Comments »
With cmt.Shape
.Width = 180 'change la taille ici en largeur
.Height = 60 'change la taille ici en hauteur
.Fill.ForeColor.RGB = vbWhite 'fond blanc
'.Line.Visible = msoFalse 'pas de bordure
End With
Else
Set cmt = Target.Comment
End If
On Error Resume Next 'empêche un débordement si déjà sélectionné
cmt.Visible = True
cmt.Shape.Select 'place le curseur dans la note
On Error GoTo 0
Set lastCmt = cmt 'nouvelle « note courante »
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not lastCmt Is Nothing Then
lastCmt.Visible = False
Set lastCmt = Nothing
End If
End Sub
Et un bonus si tu souhaites changer la couleur du texte du com (j'utilise actuellement sur mon calendrier)
je n'ai pas activé mais si tu souhaites
Code:
Option Explicit
Private lastCmt As Comment
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Const FIRST_COL As Long = 2
Const LAST_COL As Long = 4
If Target.Column < FIRST_COL Or Target.Column > LAST_COL Then Exit Sub
Cancel = True
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
If Not lastCmt Is Nothing Then
If Not lastCmt Is Target.Comment Then lastCmt.Visible = False
Set lastCmt = Nothing
End If
Dim cmt As Comment 'ou As Object si AddComment2
If Target.Comment Is Nothing Then
Set cmt = Target.AddComment("") 'AddComment2 pour Office 365 « Comments »
With cmt.Shape
''''''''BONUS''''''''
' With .TextFrame
' .AutoSize = False
' .Characters.Font.Color = RGB(0, 0, 139) ' Bleu foncé (texte)
' End With
.Width = 180 'change la taille ici en largeur
.Height = 60 'change la taille ici en hauteur
.Fill.ForeColor.RGB = vbWhite 'fond blanc
'.Line.Visible = msoFalse 'pas de bordure
End With
Else
Set cmt = Target.Comment
End If
On Error Resume Next 'empêche un débordement si déjà sélectionné
cmt.Visible = True
cmt.Shape.Select 'place le curseur dans la note
On Error GoTo 0
Set lastCmt = cmt 'nouvelle « note courante »
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not lastCmt Is Nothing Then
lastCmt.Visible = False
Set lastCmt = Nothing
End If
End Sub
re
je repete @Nicolas le select ne suffit pas a mettre le comm en mode edition
cmt.Shape.Select 'place le curseur dans la note
c'est faux pas sur tout les versions d'excel
re
je repete @Nicolas le select ne suffit pas a mettre le comm en mode edition
cmt.Shape.Select 'place le curseur dans la note
c'est faux pas sur tout les versions d'excel
le select selectionne la shape du ,commentaire c'est tout
faire les 3 sendkeys comme je fait dans mon exemple pour être sur d'avoir le carrêt (tu l'apelle le curseur)clignotant dans le comm si on veut qu'il soit en mode edition
sinon tu est obligé de cliquer dessus pour pourvoir écrire (taper dedans)
- 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