Professional Documents
Culture Documents
Commondialogbox or Common Dialog Control
Commondialogbox or Common Dialog Control
Commondialogbox or Common Dialog Control
The Common Dialog control provides a standard set of dialog boxes for operations such as
opening, saving, and printing files, as well as selecting colors and fonts and displaying help.
The Common Dialog control an "Active X" control that must be added to the toolbox via the
Components dialog box, as shown below. This dialog box is accessed via the Project menu,
Components item. Once you check "Microsoft Common Dialog Control 6.0" and click OK,
the control is added to your toolbox
ShowColor
ShowFont
The ShowFont method is used to display a list of fonts that are available.
CommonDialog1.ShowFont
Text1.FontName = CommonDialog1.FontName
Text1.FontSize = CommonDialog1.FontSize
ShowHelp
The HelpFile and HelpCommand properties must be set in order for the Help file to be
displayed.
CommonDialog1.HelpFile = "e:\vbaf\helpfile.hlp"
CommonDialog1.ShowHelp
ShowOpen
The ShowOpen method is used to display the dialog to open files. The FileName Property is
used to determine the name of the file the user selected.
The Filter Property is used to determine the types of file to be shown.
CommonDialog1.ShowOpen
Msgbox commondialog1.filename
CommonDialog1.ShowOpen
Image1.Picture = LoadPicture(CommonDialog1.FileName)
ShowPrinter
The following example uses the ShowPrinter method with the Printer object to set the number
of copies and page orientation.
CommonDialog1.ShowPrinter
Printer.Copies = CommonDialog1.Copies
Printer.Orientation = CommonDialog1.Orientation
ShowSave
The ShowSave method looks exactly the same as the ShowOpen method, except the default
title is "Save As" rather than "Open".
Dim fso As New FileSystemObject ' project -> references -> microsoft scripting runtime
Dim file1 As TextStream
CommonDialog1.ShowSave
Set file1 = fso.CreateTextFile(CommonDialog1.FileName, True)
file1.WriteLine "visual basic common dialog control example"
file1.Close