How to Use Multiple OK Buttons in an Excel Dialog Box

Last reviewed: November 2, 1994
Article ID: Q40185
The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 5.0
  • Microsoft Excel for OS/2, versions 2.2, 2.21, and 3.0

SUMMARY

If you use multiple OK buttons in a user-defined dialog box in Microsoft Excel (dialog item numbers 1 and 3), your macro should check the DIALOG.BOX line to see what number was returned. If that cell returns a FALSE value, then a Cancel button was chosen; otherwise, the cell returns an integer. The number represents the position of the OK button in the dialog box definition table, beginning with the second line in the table.

MORE INFORMATION

When you run the following example, a dialog box that contains three buttons is displayed on the screen. If you choose the first one, cell A2 returns the number 1 because the first button is the second item in the dialog box definition table. If you choose the second button, which is a Cancel button, then cell A2 returns the value FALSE. If you click the third button, then cell A2 returns the number 3.

A1: Button_Macro A2: =DIALOG.BOX(B3:H5) A3: =RETURN()

B2: item C1:  x  D1:  y  E1: width F1: height G1:  text   H1:init/result
B3:  12  C2:  0  D2:  0  E2:  165  F2:  100   G2:            H2:
B4:   1  C3: 20  D3: 15  E3:  120  F3:  21    G3: Default OK H3:
B5:   2  C4: 20  D4: 40  E4:  120  F4:  21    G4: Cancel     H4:
B6:   3  C5: 20  D5: 65  E5:  120  F5:  21    G5: OK         H5:

Note that in Microsoft Excel version 5.0, you can also use a Dialog sheet to create a user-defined dialog box with multiple OK buttons. For more information about dialog box controls in Microsoft Excel version 5.0, see Chapter 11, "Controls and Dialog Boxes," in the "Microsoft Excel Visual Basic User's Guide".


KBCategory: kbusage
KBSubcategory:

Additional words: 2.00 2.01 2.10 2.21 2.20 3.00 4.00 5.00


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 2, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.