Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

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


View products that this article applies to.

Summary

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

↑ Back to the top


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

↑ Back to the top


References

For more information about comments, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type comment in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

↑ Back to the top


Keywords: KB259292, kbprogramming, kbhowto, kbcode

↑ Back to the top

Article Info
Article ID : 259292
Revision : 6
Created on : 10/10/2006
Published on : 10/10/2006
Exists online : False
Views : 205