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.
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
filename.cpl : The name of one of the Control Panel *.CPL files.
n : The zero-based number of the applet within the *.CPL file.
t : The number of the tab (for multi-tabbed applets).
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 . |