PRB: GeoFacts Sample Causes Type Mismatch Error with Excel 97Last reviewed: December 16, 1997Article ID: Q178166 |
The information in this article applies to:
SYMPTOMSThe GeoFacts.vbp sample project that ships with Visual Basic 5.0 fails with the following run-time error when run on a machine that has Excel 97 for Windows installed:
Run-time error '13': Type mismatchThis error does not occur on a machine that has Excel 95 for Windows installed.
CAUSEThe Type Mismatch error occurs on the following line of code:
Set shtWorld = GetObject("world.xls")The GetObject function, when passing a workbook file argument, returns a Worksheet object when using Excel 95 but returns a Workbook object when using Excel 97. The Type Mismatch error occurs because the shtWorld variable is declared as Excel.Worksheet, which is not compatible with a Workbook object.
RESOLUTIONTo make the project compatible with Excel 97 for Windows, you must change the following line of code (located in the General Declarations section of Module1):
Public shtWorld As Excel.Worksheetto:
Public shtWorld As Excel.Workbook -or- Public shtWorld As ObjectNOTE: Declaring the variable as Object allows the project to run with both Excel 95 and Excel 97.
STATUSThis behavior is by design.
MORE INFORMATIONThe GeoFacts.vbp sample project was designed for Excel 95. However, you can write your automation code so that it is compatible with both Microsoft Excel 95 and Microsoft Excel 97. See the REFERENCES section below for more information.
REFERENCESFor more information regarding how to make automation code compatible with multiple versions of Excel please see the following articles in the Microsoft Knowledge Base:
ARTICLE-ID: Q143461 TITLE : XL97: CreateObject and GetObject Work Differently ARTICLE-ID: Q178167 TITLE : GeoFacts Sample Causes Automation Error on NT Keywords : vb5all VBKBAutomation Version : WINDOWS:5.0,97 Platform : WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |