CommonDialog Class Module (VBCCRCommonDialog)
The CommonDialog class module provides standard Windows common dialog functionality, including Open File, Save File, Color Selection, Font Selection, and Print dialogs.
Properties
Basic Properties
CancelError
- Whether to generate an error on cancelFlags
- Dialog flagsFilterIndex
- Currently selected file type indexDefaultExt
- Default file extensionDialogTitle
- Dialog titleFileName
- File nameFilter
- File type filterInitDir
- Initial directoryMaxFileSize
- Maximum file name length
Font Dialog Properties
FontBold
- Whether font is boldFontItalic
- Whether font is italicFontName
- Font nameFontSize
- Font sizeFontStrikethru
- Whether font has strikethroughFontUnderline
- Whether font is underlinedMin
- Minimum font sizeMax
- Maximum font size
Color Dialog Properties
Color
- Selected colorCustomColors
- Custom colors array
Print Dialog Properties
Copies
- Number of copiesFromPage
- Starting pageToPage
- Ending pageMin
- Minimum page numberMax
- Maximum page numberPrinterDefault
- Whether to use default printerOrientation
- Print orientation
Methods
ShowOpen
- Display Open File dialogShowSave
- Display Save File dialogShowColor
- Display Color Selection dialogShowFont
- Display Font Selection dialogShowPrinter
- Display Print dialogShowHelp
- Display Help dialog
Code Examples
File Dialogs
vb
Private Sub ShowOpenFileDialog()
Dim CommonDialog1 As New VBCCRCommonDialog
With CommonDialog1
.DialogTitle = "Open File"
.CancelError = True
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 1
.DefaultExt = "txt"
.InitDir = App.Path
On Error GoTo CancelError
.ShowOpen
' Process selected file
If LenB(.FileName) > 0 Then
Debug.Print "Selected file: " & .FileName
End If
End With
Exit Sub
CancelError:
If Err.Number = cdlCancel Then
Debug.Print "User cancelled the operation"
End If
End Sub
Private Sub ShowSaveFileDialog()
Dim CommonDialog1 As New VBCCRCommonDialog
With CommonDialog1
.DialogTitle = "Save File"
.CancelError = True
.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
.FilterIndex = 1
.DefaultExt = "txt"
.InitDir = App.Path
On Error GoTo CancelError
.ShowSave
' Process selected file
If LenB(.FileName) > 0 Then
Debug.Print "Save file as: " & .FileName
End If
End With