[réSoLu] code permettant d'insérer un commentaire par clic droit, non conforme

  • Initiateur de la discussion Initiateur de la discussion anthoYS
  • 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 !

anthoYS

XLDnaute Barbatruc
bonjour,


dans le présent code* nous pouvons juste ajouter un commentaire par clic droit que dans certaines colonnes, or je souhaite cela sur beaucoup plus de colonne, admettons A:ZZS
comment procéder sans le faire un à un à la manière du code ?


merci
à+


*
Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Set Target = ActiveCell
Cancel = True
With Target
   If .Column = 9 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 50.5
            .Comment.Shape.Height = 10.75
        End If
        SendKeys "%im"
    End If
    If .Column = 8 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 110.5
            .Comment.Shape.Height = 15.75
        End If
        SendKeys "%im"
    End If
     If .Column = 7 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 130.5
            .Comment.Shape.Height = 19.75
        End If
        SendKeys "%im"
    End If
         If .Column = 10 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 170.5
            .Comment.Shape.Height = 38.75
        End If
        SendKeys "%im"
    End If
          If .Column = 20 Then
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 360.5
            .Comment.Shape.Height = 200.75
        End If
        SendKeys "%im"
    End If
End With
End Sub
 
Re : code permettant d'insérer un commentaire par clic droit, non conforme

Bonjour à tous,

Peux-tu essayer ceci (hauteur et largeur à "régler" mais identiques pour tous les commentaires) :

VB:
Option Explicit


Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    Set Target = ActiveCell
    Cancel = True
    With Target
        Cancel = True
        If .Comment Is Nothing Then
            .AddComment
            .Comment.Shape.Width = 50.5
            .Comment.Shape.Height = 10.75
        End If
        SendKeys "%im"
End With
End Sub

A + à tous
 
- 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
12
Affichages
783
Réponses
6
Affichages
1 K
Retour