XL97: How to Determine If the Active Cell Contains a Comment (158246)
The information in this article applies to:
- Microsoft Excel 97 for Windows
This article was previously published under Q158246 SUMMARY
Microsoft Excel 97 no longer uses cell notes; instead Excel 97 uses
cell comments. Consequently, the macro code you use to determine whether a
cell contains a comment is different. This article discusses ways to
programmatically determine whether a cell contains a comment and discusses
compatibility issues with earlier versions of Microsoft Excel.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either
expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes
that you are familiar with the programming language being demonstrated and the
tools used to create and debug procedures. Microsoft support professionals 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 needs. If you have limited programming experience, you may
want to contact a Microsoft Certified Partner or the Microsoft fee-based
consulting line at (800) 936-5200. For more information about Microsoft Certified
Partners, please visit the following Microsoft Web site:
For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:
Checking for Cell Notes
In earlier versions of Microsoft Excel you can use a macro, like the
following one, to determine whether the active cell contains a cell note:
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 contain a cell note, a
message box displays the message "cell has no note."
NOTE: To support backward compatibility, this macro runs successfully in Microsoft Excel 97, even though it converts all cell notes to cell comments when you open a Microsoft Excel 5.0 or 7.0 file in Microsoft Excel 97.
To ensure that your macro works in all versions of Microsoft
Excel that support Visual Basic for Applications, use a macro that is similar to the example provided above.
Checking for Cell Comments
To ensure future compatibility with Microsoft Excel and specifically with
cell comments, you may want to use the Comment property
in your Visual Basic macro. The following macro uses the Comment property for a Range object to return a Comment object. If the active cell does not have a comment, the Comment property returns Nothing.
Sub Has_Comment()
Set mycomment = ActiveCell.Comment
If mycomment Is Nothing Then
MsgBox "no comment in cell"
Else
MsgBox mycomment.Text
End If
End Sub
NOTE: The Has_Comment macro does not work in earlier versions of Microsoft Excel.
REFERENCES
For more information about cell comments, follow these steps:
- Type Comment on a blank line on a module sheet.
- Select the word Comment that you typed in step 1.
- Press F1 to display the Help topic for the Comment property.
Modification Type: | Minor | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbcode kbhowto kbProgramming kbualink97 KB158246 |
---|
|