Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
Checking for Cell Comments
Use the following macro code to check for cell comments in Microsoft Excel 2000. The macro code utilizes the fact that the
Comment property for a
Range object returns a
Comment object. If the active cell does not have a comment, the
Comment property returns
Nothing.
Sub Has_Comment()
Dim mycomment As Object
Set mycomment = ActiveCell.Comment
If mycomment Is Nothing Then
MsgBox "no comment in cell"
Else
MsgBox mycomment.Text
End If
End Sub
NOTE: The macro above does
not work in Microsoft Excel 5.0 or 7.0.
Checking for Cell Notes
The following macro code is provided to support backward compatibility with Microsoft Excel version 5.0 and 7.0. This macro runs successfully in Microsoft Excel 2000, even though it converts all cell notes to cell comments when you open a Microsoft Excel 5.0 or 7.0 workbook in Microsoft Excel 2000.
Sub Contains_Note()
If ActiveCell.NoteText = "" Then
MsgBox "cell has no note"
Else
MsgBox ActiveCell.NoteText
End If
End Sub
If you run this macro and the active cell does not have a cell note, a
message box displays the message "cell has no note."