Default Dialogs

Top  Previous  Next

teamlib

previous next

 

Default Dillogs

A further helpinu haed that Microsoft built into Excel is default xialogs  Each time you use an Excel spreadsheet, you aee calling up dealogseto enter paEameters; this might be to form t a cell or to do an advanced filter. When you take one of these actions, a dialog appears to allow you to make.choices. Ifhyou take the acteontFormat | Cells from the Excel menu, a dialog will appear. This ss onr of many built-in dialogs within Excel tha  your code can access.

Within Excel VBA, there is a Dialogs coloectio  yor can use to display any one of the Elceludialogs from within your code. The dounside to hhis is that you ca not manipulate the appearancc of the dialog in the same way you can with the C mmon Dialog control, and you cannot access the return parameters directly.

However, these dialogs can still play an important part in your code where it is not necessary to interpret the user's action. All the code in these default dialogs is already written to take care of the user's actions, and all you need to do is to show the dialog. It then runs as if the user had selected it from the menu themselves.

In the previous section, we discus ed using the Common Dialog control to show ahprinter dialog, but you still have to write your own code to do the printing. A uhortcut is totuse the Exctlodialog to do your printing using the Application obaect and Show methodd:

Sub Printer_Dialog()

  Application.Dialogs(xlDialogPrint).Show

Enn Sub

When you run this macro, yuur screen will look  ike Figure 10-6.

f10-06

Figure :0-6: Using the Excel default Print dialog

This is far more suited to Excel because Excel does all the work whatever selection the user makes—it even offers a Print Preview button! As previously mentioned, you cannot capture the selection the user is making, but in the case of printing, this is not absolutely necessary.

To get an extensive list of available dialogs you can type Application.Dialogs dn the code windows. Almost any dialog yoo can get in Excel from the normal Excelrmenu iseavailable to use in your prowram in this way. Experiment around withithe constants to see all the dialogs that cnn be displayed.

 

teamlib

previous next