This file and the source code is copyrighted material which may not be published in any form without explicit prior permission from the author. However, you are free to use the source code in your private, non-commercial, projects without permission. You are allowed to use these functions and routines in commercial products, provided the documentation of these products makes a reference to the original source. The following reference is recommended:

 

(PART OF) THIS SOFTWARE IS BASED ON SOURCE CODE, ORIGINALLY CREATED BY ROMKE SOLDAAT (mailto:ROMKE@SOLDAAT.COM), AND PUBLISHED IN MICROSOFT OFFICE & VISUAL BASIC FOR APPLICATIONS DEVELOPER, BY INFORMANT COMMUNICATIONS GROUP (http://www.informant.com/)

ComDlgEx.cls Properties and Methods

If you want to use the common dialog boxes with their extended properties, you must include both the ComDlgEx.cls and ComDlgHook.bas modules in your VB or VBA project. If you also want to use the dialog template described in this article, you must install the COMDLGEX.DLL file in your Windows folder. If you don't have the VB 6 runtime files (which must be on your system if you want to use COMDLGEX.DLL), you can download them from http://support.microsoft.com/support/kb/articles/Q235/4/20.asp.

 

The following examples demonstrate the use of the ComDlgHook properties and methods:

 

Sub Example1()

With New ComDlgEx

  .CheckBoxSelected = True

  .CheckBoxCaption = _

    "&Set selected folder as default Backup destination"

  .FileName = ActiveDocument.Name

  .DialogTitle = "Backup Document"

  .txtButtonOK = "&Backup"

  .txtLabelLookIn = "&Save copy in:"

  .IconFile = Application.Path & "\winword.exe"

  .IconIndex = 0

  Dim flt(3) As String

  flt(0) = "Documents|*.doc"

  flt(1) = "Templates|*.dot"

  flt(2) = "Wizards|*.wiz"

  flt(3) = "All Files|*.*"

  .Filter = flt

  If .ShowSave Then

    MsgBox "Backing up: " & .FileName

    If .CheckBoxSelected Then

      MsgBox "Folder selected: " & .Directory

    End If

  End If

End With

End Sub

 

Sub Example2()

Dim Dlg As ComDlgEx

Set Dlg = New ComDlgEx

With Dlg

  .AllowMultiSelect = True

  .CenterDialog = CenterOwner

  .DialogTitle = "Mini File Manager"

  .TemplateLibrary = "COMDLGEX.dll"

  .TemplateID = 100

  .StatusbarVisible = True

  .txtButtonOK = "OK"

  .txtButtonCancel = "&Close"

  .HelpMessage = "This is the Help text"

  .IconFile = "EXPLORER.EXE"

  .IconIndex = 1

  .txtButton1 = "&Copy..."

  .txtButton2 = "&Move..."

  .txtButton3 = "&Delete"

  .txtButton4 = "&Print"

  .txtButton5 = "&About..."

  .Filter = "All Files|*.*"

  If .ShowOpen Then

    For Each F In .FileNames

      MsgBox F

    Next

  End If

End With

Set Dlg = Nothing

End Sub

 

AllowMultiSelect property

Boolean. Default value is False. If set to True, the common dialog allows multiple file selections. Ignored if the Save As dialog is displayed.

 

CenterDialog property

Long. Use one of the following enumeration variables: DontCenter, CenterOwner, or CenterScreen. The default is DontCenter.

 

CheckBoxCaption property

String. The text that replaces the "Open as read-only" checkbox caption. Setting a value for this property automatically makes the checkbox visible. Use the CheckBoxSelected property to preselect the checkbox, and to read the selected status when the dialog closes.

 

CheckBoxSelected property

Read/write Boolean. Default value is False. If set to True, the common dialog displays and selects the Read-Only checkbox.

On return, the True/False value of this property indicates whether the user selected or unselected the checkbox.

 

CheckBoxVisible property

Boolean. Default value is False. If set to True, the common dialog displays the Read-Only checkbox. If the CheckBoxSelected property is set to True, CheckBoxVisible is automatically also set to True.

 

DialogTitle property

String. Specifies the title bar text. Especially useful if you don't want to use the dialog box to open or save a file, but need a file name (or a list of file names) for another purpose. If omitted, Windows uses the default caption ("Open" or "Save As").

 

Directory property

Read/Write String. Specifies the initial path in the dialog. If omitted, the initial path is determined by the operating system. (See also FileName property.)

On return, this property contains the path in which the user has selected the file(s).

 

ExistFlags property

Long. Use any combination of the following enumeration variables: PathMustExist,  FileMustExist, and  PromptToCreateFile. PathMustExist is automatically set if the Save As dialog is displayed.

 

Extension property

Read/Write String. Specifies the extension appended to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. If this property is not specified and the user doesn't type an extension, no extension is appended.

On return, this property contains the extension of the selected file. If multiple files are selected, the return value is an empty string.

 

FileName property

Read/Write String. Specifies the file name used to initialize the "File name" edit control. If the specified filename contains a path name, and no value is specified for the Directory property, Windows 98 and earlier versions use the path component of FileName to initialize the dialog. Windows 2000 uses this path to initialize the dialog, even if a value is specified for the Directory property.

On return, this property contains the name (including the path) of the selected file. If multiple files are selected, this property contains an empty string; use the FileNames property instead.

 

FileNames property

Read-Only Collection. On return, contains the names (including the path) of all selected files. Use FileNames.Count to obtain the number of selected files. See the first example for its implementation. If the Save As dialog is displayed, this collection contains a single file name.

 

FileTitle property

Read-Only String. On return, this property contains the name (without the path) of the selected file. If multiple files are selected, this property contains an empty string; use the FileTitles property instead.

 

FileTitles property

Read-Only Collection. On return, contains the names (without the path) of all selected files. Use FileTitles.Count to obtain the number of selected files. If the Save As dialog is displayed, this collection contains a single file title. Returning file titles is especially useful if you have a form with a listbox that you want to fill with file names.

 

Filter property

Read/write Variant. Specifies the filters in the "Files of type" list. Can be a single string, or an array of strings. Filters are pairs of strings, separated by a pipe symbol (|). The first string in each pair is a string that describes the filter (for example, "Documents"), the second string specifies the filter pattern (for example, "*.doc"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.doc;*.dot;*.wiz"). A pattern string can be a combination of valid file name characters and the asterisk (*) or question mark wildcard character (e.g. "*.do?"). Do not include spaces in the pattern string. See the examples for its implementation.

On return, this property contains the filter selected by the user.

 

FilterIndex property

Read/write Long. Specifies the initial index of the selected filter in the "Files of type" list. The first filter has an index value of 1, the second filter 2, etc..

On return, this property contains the index of the filter selected by the user.

 

HideControls property

Long. Lets you hide the folder list, the "File name" edit box, and the "Files of type " list. Use any combination of the following enumeration variables: HideLookInListbox,  HideFileNameTextbox, and  HideFileTypeListbox. The associated labels are also automatically hidden.

 

IconFile property

String. The full path of the file that contains the icon you want to display on the itle bar. If no value is specified, no icon is displayed.

 

IconIndex property

Long. The zero-based index of the icon in IconFile. If the icon is a single .ICO file (rather than an icon in an .EXE or .DLL file), this property can be omitted.

 

RestoreCurDir property

Boolean. Default value is False. If set to True, the common dialog restores the current directory to its original value if the user changed the directory while searching for files.

 

ShowOpen method

Displays the Open dialog. Returns True if one or more files were selected, False if the user clicked the Cancel button.

 

ShowSave method

Displays the Save As dialog. Returns True if a file was selected, False if the user clicked the Cancel button.

 

StatusbarVisible property

Boolean. Set to True to display the status bar.

 

TemplateLibrary property

String. The name of the DLL file that contains the dialog template. If the DLL isn't installed in the Windows folder you must specify the full path of the file. If you want to use the DLL shipped with the download file, specify "COMDLGEX.DLL".

 

TemplateID property

Long. The ID of the template in the resource file specified in TemplateLibrary. If you want to use the DLL shipped with the download file, specify 100 for TemplateID.

 

txtButton1, txtButton2, txtButton3, txtButton4, txtButton5 properties

Strings. The caption of the five buttons in the dialog template in COMDLGEX.DLL .If no string for a button is specified, the button is automatically hidden.

 

txtButtonCancel property

String. The text on the Cancel button. An alternative caption could be "Close".

 

txtButtonHelp property

String. The text on the Help button. Suggestions for alternative strings are: "About" or "Info". The Help button is only displayed if also a value if specified for the HelpMessage property. Clicking the Help button displays the help message in a message box.

 

txtButtonOK property

String. The text on the default Open or Save As button. Especially useful if your dialog isn't designed to open or save files.

 

txtLabelFileName property

String. The text in front of the "File name" edit box. It is generally not recommended to change this string.

 

txtLabelFileType property

String. The text in front of the "Files of type " dropdown list. Think twice before you decide to modify this string.

 

txtLabelLookIn property

String. The text in front of the dropdown folder list. By default, the string is "Look in:" or "Save in:". It may be useful to change this string if your dialog isn't supposed to return files that you want to open or save.

 

Romke Soldaat

July 21, 2000