Running Control Panel Dialog Boxes


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.

image from book
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 
  • 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 image from book  control panel dialogs.xlsm .

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



Excel 2007 Power Programming with VBA
Excel 2007 Power Programming with VBA (Mr. Spreadsheets Bookshelf)
ISBN: 0470044012
EAN: 2147483647
Year: 2007
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net