Microsoft KB Archive/114183

= Microsoft Knowledge Base =

XL: Error Message Using Name of Constant with Show Method
Last reviewed: June 26, 1997

Article ID: Q114183

The information in this article applies to:


 * Microsoft Excel for Windows, versions 5.0, 5.0c
 * Microsoft Excel for the Macintosh, versions 5.0, 5.0a
 * Microsoft Excel for Windows 95, version 7.0, 7.0a

SUMMARY
When you use the Show method of the Dialog Object in a Visual Basic macro in Microsoft Excel, and you use the name of a built-in constant as the value of an argument, the following error message may appear:

Run-time error '1004':

Show method of Dialog class failed

CAUSE
This behavior is by design in Microsoft Excel. You cannot use the name of a built-in constant as an argument for the Show method of the Dialog Object. Because some constants are used as arguments for multiple dialog boxes, there is no way to uniquely identify a constant by name.

WORKAROUNDS
To avoid receiving this error message when you use arguments with the Show method of the Dialog object, use the value of the argument as determined by the Microsoft Excel version 4.0 macro command instead of the name of the constant. For example, if you are using the Show method to display the Save As dialog box, and you want to save the file to the Microsoft Excel Workbook file format, use the following code:

Sub SaveAs_Dlg Application.Dialogs(xlDialogSaveAs).Show arg1:="TEST.XLS", arg2:=1 End Sub When you run this macro, the Save As dialog box appears and Microsoft Excel Workbook is selected in the Save File As Type list because the value of the Microsoft Excel workbook file format argument is 1.

Microsoft provides examples of Visual Basic for Applications 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

MORE INFORMATION
To find the value of an individual argument to use with the Show method of the Dialog object in Microsoft Excel, do the following:


 * 1) In Microsoft Excel 5.0 Help, click Reference Information. In Microsoft Excel 7.0, click the Contents tab and double-click Microsoft Excel Visual Basic Reference.
 * 2) In Microsoft Excel 5.0, click Microsoft Excel Macro Functions Contents in the Reference Information window. In Microsoft Excel 7.0, double-click Functions.
 * 3) In Microsoft Excel 5.0, click the Alphabetical List Of Macro Functions option. In Microsoft Excel 7.0, double-click the letter of the alphabet that corresponds to the first letter of the function name.
 * 4) In the alphabetized list, click the command that corresponds to the dialog box you want to display using the Show method. For example, if you want to display the Save As dialog box using the Dialog object, select the Save.As command from the list.