Clear Comment problem

  • Thread starter saman110 via OfficeKB.com
  • 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
 
J

JLatham

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.
 
S

saman110 via OfficeKB.com

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top