Excel: Error Checking in Macros and File CommandsLast reviewed: July 16, 1997Article ID: Q92557 |
The information in this article applies to:
SUMMARYIn Microsoft Excel, you can use an error checking routine in a macro to determine if a condition exists and then specify what should happen. The following two macros use IS functions to determine if a certain condition exists.
Macro to Check for a File Called SHEET1.XLS
=ERROR(FALSE) =IF(ISERROR(ACTIVATE("sheet1.xls")),OPEN("sheet1.xls")) =ERROR(TRUE)In the event of an error, ERROR(FALSE) allows the macro to continue without displaying an error message. ERROR(TRUE) resets error checking to normal. If the document is open, Microsoft Excel will activate the document. Otherwise, the ACTIVATE statement produces an error and ISERROR returns a true condition. This causes the IF statement to run the OPEN statement to open SHEET1.XLS.
Formula to Determine if Menu Item ExistsThe following formula allows Microsoft Excel to determine if a menu item exists. If the menu item does not exist, it is added to the menu. =IF(ISNA(GET.BAR(1,OFFSET(network,0,0,1,1),0)),ADD.MENU(1,network,9)) The defined name given to the menu definition table is "network." The OFFSET function returns the top left cell of the menu definition table which is the name of the menu itself. If the menu exists, the GET.BAR function will return a number equal to the position of the menu item. If the menu does not exist, the GET.BAR function will return the #N/A value at which point the IF statement will run the ADD.MENU function.
MORE INFORMATIONFor more information on ISERROR, ISNA, GET.BAR, and other functions, refer to the "Microsoft Excel Function Reference."
REFERENCES"Microsoft Excel Function Reference," version 4.0, 10, 35, 190-191 "Microsoft Excel Function Reference," version 3.0, 68, 135-136
|
Additional query words: 5.00 3.00 4.00 3.0 4.0 error
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |