Sub vbutton()
Dim strComments As String
strComments = InputBox("Please Type your comment","Enter Comment","")
If Len(strComments) 0 Then
ActiveCell.AddComment
ActiveCell.Comment.Visible = False
ActiveCell.Comment.Text Environ$("USERNAME") & Chr(10) & strComments
If Cancel = True Then
ActiveCell.ClearComments
End If
End If
End Sub
The revision to the InputBox statement makes an empty string the default,
the new IF test will test content of strComment and if it is empty, will not
add a comment to the cell.
"saman110 via OfficeKB.com" wrote:
hello,
I want to get the code below to stop inserting comment when I hit cancel. Any
help?
Thx.
Sub vbutton()
Dim strComments As String
strComments = InputBox("Please Type your comment")
ActiveCell.AddComment
ActiveCell.Comment.Visible = False
ActiveCell.Comment.Text Environ$("USERNAME") & Chr(10) & strComments
If Cancel = True Then
ActiveCell.ClearComments
End If
End Sub
--
Message posted via http://www.officekb.com