Microsoft KB Archive/184096

From BetaArchive Wiki

Article ID: 184096

Article Last Modified on 6/17/2005



APPLIES TO

  • Microsoft Excel 98 for Macintosh



This article was previously published under Q184096


SUMMARY

Microsoft Excel 98 Macintosh Edition no longer uses cell notes; instead, Excel 98 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 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 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 98 even though it converts all cell notes to cell comments when you open a Microsoft Excel version 5.0 file in Microsoft Excel 98.

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()
       Dim mycomment As 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, from the Visual Basic Editor, click the Office Assistant, type comment, click Search, and then click to view "Comment Property."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

176476 OFF: Office Assistant Not Answering Visual Basic Questions



Additional query words: vbe XL98

Keywords: kbhowto kbprogramming kbdtacode KB184096