Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the CFileDialog class. |
DefaultExt | Property | Get the default extension. |
DialogTitle | Property | Get the title displayed in the dialog. |
FileName | Property | Get the path and filename. |
FileTitle | Property | Get the file name without the path. |
Filter | Property | Get the current filter value. Use this property to provide the user with a list of file types that can be selected when the dialog box is displayed. |
FilterIndex | Property | Get the index of the filter to display. |
Flags | Property | Get the current flags. |
hWndParent | Property | Get the parent hWnd. |
InitialDir | Property | Get the initial directory (folder) path where the dialog opens. |
MaxFileSize | Property | Get the maximum length of the filename. |
Class_Initialize | Initialize | Initialize the class. |
GetFileName | Method | Display the Windows file Open/Save common dialog and retrieve the file name. This function eliminates the need to set individual properties. |
Show | Method | Display the file Open/Save common dialog. |
TrimNulls | Private | Get the passed string, terminated at the first single or double null character. If multiple files were selected, TrimNulls return the path, then the file names separated by spaces: e.g.: C:\Total Visual SourceBook\ install.log readme.txt. |
' Example of CFileDialog ' ' To use this example, create a new module and paste this code into it. ' Then run the procedure by putting the cursor in the procedure and pressing: ' F5 to run it, or ' F8 to step through it line-by-line (see the Debug menu for more options) Private Sub Example_CFileDialog() ' Comments: Examples of using the CFileDialog class to invoke the Windows API Common Control for selecting a file or files from the File Dialog in VBA and VB6. Const cstrSamplePath As String = "C:\Total Visual SourceBook 2013\Samples\" Dim strFile As String Dim clsFileDialog As CFileDialog Set clsFileDialog = New CFileDialog With clsFileDialog ' Use the GetFileName method to Display the file open dialog and retrieve the file name ' This method accepts parameters rather than requiring the class properties to be set. strFile = .GetFileName(True, "*.txt", "Total Visual SourceBook Example of File Open", "Text files (*.txt)|*.txt|All Files (*.*)|*.*") If strFile <> "" Then MsgBox "You chose this file: " & strFile Else MsgBox "You cancelled the File Open dialog" End If ' Use the Show method to show the "Save" dialog. ' First set the properties for the class. .DefaultExt = "txt" .DialogTitle = "Total Visual SourceBook Example of File Save" .Filter = "Text files (*.txt)|*.txt|All Files (*.*)|*.*" .FilterIndex = 0 .Flags = FleFileMustExist + FleHideReadOnly + FleCreatePrompt .hWndParent = 0 ' Use your form's .hwnd property if available .InitialDir = cstrSamplePath ' Initial folder, can also be a file name .MaxFileSize = 255 If .Show(False) Then MsgBox "File Name: " & .FileTitle & vbCrLf & "Full Path: " & .FileName Else MsgBox "You cancelled the File Save dialog" End If End With Set clsFileDialog = Nothing End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP