Microsoft KB Archive/213588

= XL2000: Styles("X").Parent Different Than in Earlier Versions of Excel =

Article ID: 213588

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 2000 Standard Edition

-



This article was previously published under Q213588





SYMPTOMS
When you run a Microsoft Visual Basic for Applications macro in Microsoft Excel, your macro may behave incorrectly if it accesses the Parent property of a Style object (Styles.Parent).



CAUSE
This behavior may occur because the Parent property of a Style object changed in Microsoft Excel 97:

  Versions                   Parent Property of Style Object Returns --  Microsoft Excel 97, 2000   a Workbook object Microsoft Excel 5.0, 7.0  the Application object

This behavior is by design of Microsoft Excel. The behavior in versions of Microsoft Excel earlier than Excel 97 is incorrect.



WORKAROUND
If your macro contains code that accesses the Parent property of a Style object, and you expect the Parent property to return the Application object, you must remove "Parent" from your macro and replace it with "Application". If you do this, the macro will work correctly in all versions of Microsoft Excel that contain Visual Basic for Applications.

For example, assume your macro contains the following line of code:

X = ActiveWorkbook.Styles(1).Parent.Name

You would change this line to:

X = ActiveWorkbook.Styles(1).Application.Name



MORE INFORMATION
In Microsoft Excel, almost every type of object has a Parent property. The Parent property of an object returns the larger object that contains it. For example, ActiveCell.Parent returns the worksheet that contains the active cell.

In versions of Microsoft Excel earlier than Excel 97, the Parent property of a Style object is the Application object ("Microsoft Excel"). This is actually incorrect; the Parent property of a Style object should be the Workbook object that actually contains the style. This change is now incorporated in Microsoft Excel.

Additional query words: 9.00 XL2000

Keywords: kbprb kbprogramming KB213588

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.