The information in this article applies to:
SYMPTOMSWhen you run a macro in Microsoft Excel 97 for Windows that attempts to select a worksheet that does not exist in a workbook, you may receive the following error message: This error message is different from the error message that you receive in earlier versions of Microsoft Excel. RESOLUTIONMicrosoft provides programming examples 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 article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspIn earlier versions of Microsoft Excel, when a macro attempts to select a sheet that does not exist in a workbook, you receive the following error message: The new error message reflects the fact that the Sheets Collection object in Microsoft Excel 97 returns an array of all sheets in a workbook. The error message "Subscript out of range" indicates that the macro references a nonexistent array element or collection member. The subscript may be larger or smaller than the range of possible subscripts, or the array may not yet have assigned dimensions in the application. Because the error code has changed, when you write an error handling routine that specifically tests for this run-time error, make sure that your routines reflect the new error code, and not the error code from previous versions. The following sample demonstrates how to use an error handling routine and a routine that tests whether a worksheet exists in Microsoft Excel 97:
If you run the preceding macro in a workbook that does not have a sheet
called "nonexistent," a message box with the following message appears:
REFERENCESFor more information about the Sheets Collection object, click the Index tab in Microsoft Visual Basic Help, type the following text sheetsand then double-click the selected text to go to the "Sheets Collection Object" topic. Additional query words: XL97
Keywords : kberrmsg kbprg kbdta kbdtacode KbVBA |
Last Reviewed: November 9, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |