Code sample:
'Add comment
Private Sub AddMyComment()
Dim MyRange As Range
Set MyRange = ActiveSheet.Cells(1, 1)
If MyRange.Comment Is Nothing Then
MyRange.AddComment
MyRange.Comment.Text "Please test adding a comment with VBA" & vbNewLine _
& "You can add"
End If
'Remove comment
Private Sub cmdRemoveComment()
Dim MyRange As Range
Set MyRange = ActiveSheet.Cells(1, 1)
If Not (MyRange.Comment Is Nothing) Then
MyRange.Comment.Delete
End If
End Sub
Or can be used like this:
'Sheet1.Range("A1").AddComment ("Please test adding a comment with VBA")
'Sheet1.Range("A1").Comment.Delete
No comments:
Post a Comment