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

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
 

JCGL

XLDnaute Barbatruc
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
 

Discussions similaires

Réponses
2
Affichages
136

Membres actuellement en ligne

Statistiques des forums

Discussions
312 206
Messages
2 086 203
Membres
103 157
dernier inscrit
youma