Help and Support

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

Article ID:157124
Last Review:October 10, 2006
Revision:1.2
This article was previously published under Q157124

SYMPTOMS

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

Back to the top

CAUSE

This may occur because the Parent property of a Style object is different in Microsoft Excel 97 than it is in earlier versions of Microsoft Excel:
   Version(s)                 Parent Property of Style Object Returns
   ------------------------------------------------------------------
   Microsoft Excel 97         a Workbook object
   Microsoft Excel 5.0, 7.0   the Application object
				
This behavior is by design of Microsoft Excel 97. The behavior in earlier versions of Microsoft Excel is incorrect.

Back to the top

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 Microsoft Excel versions 5.0, 7.0 and 97.

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
				

Back to the top

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 earlier versions of Microsoft Excel, 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 incorporated in Microsoft Excel 97.

Back to the top


APPLIES TO
Microsoft Excel 97 Standard Edition

Back to the top

Keywords: 
kbprb kbprogramming KB157124

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.