XL7: Run-time Error Using Macro to Access Worksheet in Binder

Last reviewed: September 3, 1997
Article ID: Q130101

The information in this article applies to:

  • Microsoft Excel for Windows 95, version 7.0

SYMPTOMS

In Microsoft Excel, when you use a Visual Basic, Applications Edition, procedure to create an Office Binder OLE Automation object, and you edit a Microsoft Excel worksheet object in the Binder, you may receive the following error message:

   Run-time error '438':

   Object doesn't support this property or method

CAUSE

This behavior occurs when you edit a Microsoft Excel worksheet object in a Binder using OLE Automation if you attempt to access a single sheet (such as a worksheet) or an item on a single sheet (such as a cell value) from outside the Application object without using the Parent object. This behavior occurs because the Microsoft Excel object is a worksheet, even though the section in the Binder is a workbook that you can add sheets to and so on. For example, if you use the following command in a Visual Basic procedure to add a worksheet to section 1 (a Microsoft Excel workbook) in the Binder "MyBinder," you receive the above error message:

   MyBinder.Sections(1).Worksheets.Add

If you use the following command to enter the value "test" in cell A1 on the first worksheet in section 1 (a Microsoft Excel workbook) in the Binder "MyBinder," you also receive the above error message:

   MyBinder.Sections(1).Worksheets(1).Range("A1").Value = "test"

RESOLUTION

To work around this behavior, use the Parent object to access a Microsoft Excel workbook object, and then use the property or method of the Worksheet object as in the following examples:

Microsoft provides examples of Visual Basic procedures 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 Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line- continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

The following command adds a worksheet to section 1 (a Microsoft Excel workbook) in the Binder "MyBinder":

   MyBinder.Sections(1).Object.Parent.Worksheets.Add

The following command enters the value "test" in cell A1 on the first worksheet in section 1 (a Microsoft Excel workbook) in the Binder "MyBinder":

   MyBinder.Sections(1).Object.Parent.Worksheets(1).Range("A1").Value _
     = "test"

MORE INFORMATION

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q114225
   TITLE     : XL5: OLE Automation Error Using Quit Method with GetObject


REFERENCES

For more information about "Parent Property," click the Index tab in Help and type:

   pare


Additional query words: 7.00
Keywords : IntpOthr kbcode kbinterop kbfasttip
Version : 7.0
Platform : WINDOWS
Issue type : kberrmsg
Solution Type : kbcode


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.