1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Dim WithEvents AddButton1 As CommandBarButton
Dim WithEvents AddButton2 As CommandBarButton
Event CommentAdded(Target As Range)
Private Sub Class_Initialize()
With Application.CommandBars
Set AddButton1 = .FindControl(, 1589) 'Les barres d'outils
Set AddButton2 = .FindControl(, 2031) 'Le menu contextuel
End With
End Sub
Private Sub AddButton1_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
AddComment
CancelDefault = True
End Sub
Private Sub AddButton2_Click(ByVal Ctrl As Office.CommandBarButton, _
CancelDefault As Boolean)
AddComment
CancelDefault = True
End Sub
Private Sub AddComment()
Dim CommentText As String
CommentText = InputBox("Insérer un commentaire")
If Not CommentText = vbNullString Then
With ActiveCell
.AddComment
.Comment.Text CommentText
End With
RaiseEvent CommentAdded(ActiveCell)
End If
End Sub |