Excel 2007 Power Programming with VBA (Mr. Spreadsheets Bookshelf)

Windows provides quite a few system dialog boxes and wizards, most of which are accessible from the Windows Control Panel. You might need to display one or more of these from your Excel application. For example, you might want to display the Windows Date and Time Properties dialog box, shown in Figure 20-2.

Figure 20-2: Use VBA to display a Control Panel dialog box.

The key to running other system dialog boxes is to execute the rundll32.exe application by using the VBA Shell function.

The following procedure displays the Date and Time dialog box:

Sub ShowDateTimeDlg() Dim Arg As String Dim TaskID As Double Arg = "rundll32.exe shell32.dll,Control_RunDLL timedate.cpl" On Error Resume Next TaskID = Shell(Arg) If Err <> 0 Then MsgBox ("Cannot start the application.") End If End Sub

Following is the general format for the rundll32.exe application:

rundll32.exe shell32.dll,Control_RunDLL filename.cpl, n,t

CD-ROM  

A workbook that displays12 additional Control Panel applets, depicted in Figure 20-3, is available on the companion CD-ROM. The filename is  control panel dialogs.xlsm .

Figure 20-3: The workbook that displays this dialog box demonstrates how to run system dialog boxes from Excel.

Категории