Microsoft KB Archive/259292

= XL2000: How to Determine If the Active Cell Contains a Comment =

Article ID: 259292

Article Last Modified on 10/10/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q259292





SUMMARY
This article discusses ways to programmatically determine whether a cell contains a comment and discusses compatibility issues with earlier versions of Microsoft Excel.



MORE INFORMATION
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 &quot;no comment in cell&quot; 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 = &quot;&quot; Then MsgBox &quot;cell has no note&quot; 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 &quot;cell has no note.&quot;

