XL97: Error Applying Comment When Worksheets Are Grouped (168754)
The information in this article applies to:
- Microsoft Excel 97 for Windows
This article was previously published under Q168754 SYMPTOMS
In Microsoft Excel 97, if you run a Visual Basic for Applications macro
that attempts to add a comment to a cell in a worksheet, you may receive
the following error message:
Run-time error '1004':
NoteText method of Range class failed
The same macro works without error in earlier versions of Microsoft Excel.
CAUSE
This problem occurs if the macro uses a line of code similar to the
following
ActiveCell.NoteText Text:="This is a comment."
to add a comment to a cell when two or more worksheets are grouped or
selected.
WORKAROUNDMicrosoft 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:
There are two methods you can use to prevent this problem from occurring:
Method One
Do not use the NoteText method with the ActiveCell property directly.
Instead, use the ActiveCell property to determine what cell to comment, and
then apply the comment to that cell using the Range and NoteText methods.
The following code example demonstrates one way in which this may be done.
Sub Test1()
'Use "Range(ActiveCell.Address)" in place of "ActiveCell".
Range(ActiveCell.Address).NoteText Text:="This is a comment."
End Sub
Method Two
If you want to apply the same comment to the active cell in all of the
grouped worksheets, you can use For Each and Next to loop through all of
the worksheets. The following code example demonstrates one way in which
this may be done.
Sub Test2()
'For each currently selected worksheet...
For Each xSheet In ActiveWindow.SelectedSheets
'...add a comment to the active cell in that sheet.
xSheet.Range(ActiveCell.Address).NoteText Text:="Hello!"
'Repeat for all of the grouped worksheets.
Next xSheet
End Sub
This code will apply the same comment to the active cell in all of the
grouped worksheets.
STATUS
This behavior is by design of Microsoft Excel 97.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kberrmsg kbhowto kbprb kbProgramming KB168754 |
---|
|