XL97: Parentheses Around Object May Dereference the Object (159845)
The information in this article applies to:
- Microsoft Excel 97 for Windows
This article was previously published under Q159845 SYMPTOMS
In Microsoft Excel 97, you may receive a run-time error or unexpected
results from your macro if you enclose the argument for a procedure in
parentheses when a value is not returned from the procedure. You may
receive one of the following error messages:
Run-time error '438':
Object doesn't support this property or method
Run-time error '424':
Object Required
CAUSE
You may receive one of these error messages if you enclose an object
variable with parentheses when passing the object variable to another
function or procedure. When an object variable is enclosed in parentheses
and a return value is not expected, the object variable is "dereferenced."
In other words, the Value property for the object is passed to the
procedure instead of the object itself. This can produce either a run-time
error or unexpected results.
This behavior is by design of Microsoft Excel.
RESOLUTION
To correct this problem, do not use parentheses around object variables
that are passed to a function or procedure when a return value is not
expected. Parentheses should only be used around object variables when a
return value is needed.
For example, this line produces an error in Microsoft Excel 97 because the
Worksheet object is dereferenced.
Worksheets.Add (Worksheets(1))
Since parentheses are used around the argument, it is dereferenced; the
Value property of the Worksheet object is passed to the Add method rather
than the Worksheet object itself. The following line does not generate an
error since the argument is not enclosed in parentheses and, therefore, the
Worksheet object is not dereferenced:
Worksheets.Add Worksheets(1)
REFERENCES
For more information about using parentheses in your macros, click the
Office Assistant in the Visual Basic Editor, type " parentheses," click
Search, and then click to view "Use Parentheses in Code."
NOTE: If the Assistant is hidden, click the Office Assistant button on the
Standard toolbar. If Microsoft Excel Help is not installed on your
computer, please see the following article in the Microsoft Knowledge Base:
120802
Office: How to Add/Remove a Single Office Program or Component
Modification Type: | Minor | Last Reviewed: | 10/10/2006 |
---|
Keywords: | kbdtacode kberrmsg kbProgramming KB159845 |
---|
|