Clear Comment problem

  • Thread starter Thread starter saman110 via OfficeKB.com
  • Start date Start date
S

saman110 via OfficeKB.com

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
 
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.
 
Thank you. works great.
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.
[quoted text clipped - 14 lines]
End If
End Sub
 
Back
Top