PRB: Excel Automation: Method of Object '_Global' FailedLast reviewed: December 30, 1997Article ID: Q178510 |
The information in this article applies to:
SYMPTOMSWhile running code that uses Automation to control Microsoft Excel, one of the following errors may occur. With Microsoft Excel 97, you receive the error:
Run-time error '1004': Method '<name of method>' of object '_Global' failed -or- Application-defined or object-defined errorWith Microsoft Excel 95, you receive the error:
Run-time error '-2147023174' OLE Automation error CAUSEVisual Basic has established a reference to Excel due to a line of code that calls an Excel object, method, or property without qualifying it with an Excel object variable. Visual Basic does not release this reference until you end the program. This errant reference interferes with automation code when the code is run more than once.
RESOLUTIONModify the code so that each call to an Excel object, method, or property is qualified with the appropriate object variable.
STATUSThis behavior is by design.
MORE INFORMATIONTo automate Microsoft Excel, you establish an object variable that usually refers to the Excel Application or Workbook object. Other object variables can then be set to refer to a Worksheet, a Range, or other objects in the Microsoft Excel object model. When you write code to use an Excel object, method, or property, you should always precede the call with the appropriate object variable. If you do not, Visual Basic establishes its own reference to Excel. This reference may cause problems when trying to run the automation code multiple times. Note that even if the line of code begins with the object variable, there may be a call to an Excel object, method, or property in the middle of the line of code that is not preceded with an object variable. The following steps illustrate how to reproduce this problem, and how to correct it.
Steps to Reproduce Behavior
REFERENCESFor additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q167223 TITLE : Microsoft Office 97 Automation Help File Available on MSL |
Additional query words: activex automation OLE automation
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |