Dialog Methods Reference
📋 Method List
| Method | Description |
|---|---|
ShowOpen | Show open file dialog |
ShowSave | Show save file dialog |
ShowBrowseForFolder | Show select folder dialog |
SelectFiles | Select files and return collection |
SelectAndOpenFile | Select file and open |
OpenFile | Open specified file |
AddFilter | Add file filter |
ClearFilter | Clear all filters |
SetCommonFilters | Set common filters |
SetImageFilters | Set image filters |
SetDocumentFilters | Set document filters |
SetCodeFilters | Set code filters |
GetFilePath | Get file path (without filename) |
GetFileName | Get filename (with extension) |
GetFileExtension | Get file extension |
GetFileNameWithoutExt | Get filename (without extension) |
Reset | Reset to default settings |
📂 ShowOpen Method
Description
Shows open file dialog. Returns selected file path, supports multi-select.
Syntax
Public Function ShowOpen() As VariantReturn Value
- Single select mode: Returns file path string, returns empty string on cancel
- Multi-select mode (MultiSelect=True): Returns file path array
Example
Single File Selection
Dim dlg As New cDialog
dlg.DialogTitle = "Open File"
dlg.InitialDir = "C:\Documents"
dlg.AddFilter "Text Files", "*.txt"
dlg.AddFilter "All Files", "*.*"
Dim filePath As String
filePath = dlg.ShowOpen
If filePath <> "" Then
Debug.Print "Selected file: " & filePath
End IfMulti-File Selection
dlg.MultiSelect = True
Dim result As Variant
result = dlg.ShowOpen
If IsArray(result) Then
Dim i As Long
For i = LBound(result) To UBound(result)
Debug.Print "File " & i & ": " & result(i)
Next i
ElseIf result <> "" Then
Debug.Print "Single file: " & result
End If💾 ShowSave Method
Description
Shows save file dialog.
Syntax
Public Function ShowSave() As StringReturn Value
Returns save path string, returns empty string on cancel.
Example
Dim dlg As New cDialog
dlg.DialogTitle = "Save File"
dlg.DefaultExt = "txt"
dlg.FileName = "New Document.txt"
dlg.InitialDir = "C:\Documents"
dlg.AddFilter "Text Files", "*.txt"
dlg.AddFilter "All Files", "*.*"
Dim savePath As String
savePath = dlg.ShowSave
If savePath <> "" Then
Debug.Print "Save to: " & savePath
' Execute save operation
End If📁 ShowBrowseForFolder Method
Description
Shows select folder dialog.
Syntax
Public Function ShowBrowseForFolder() As StringReturn Value
Returns selected folder path, returns empty string on cancel.
Example
Dim dlg As New cDialog
dlg.DialogTitle = "Please select output folder"
dlg.NewDialogStyle = True ' Use new style (with edit box)
Dim folderPath As String
folderPath = dlg.ShowBrowseForFolder
If folderPath <> "" Then
Debug.Print "Selected folder: " & folderPath
End If📋 SelectFiles Method
Description
Shows open file dialog, returns selected file collection (Collection).
Syntax
Public Function SelectFiles() As CollectionReturn Value
Returns Collection object containing file paths.
Example
Dim dlg As New cDialog
dlg.DialogTitle = "Select Files"
dlg.MultiSelect = True
dlg.AddFilter "All Files", "*.*"
Dim files As Collection
Set files = dlg.SelectFiles
Debug.Print "Selected " & files.Count & " files"
Dim file As Variant
For Each file In files
Debug.Print file
Next file🚀 SelectAndOpenFile Method
Description
Shows open file dialog and automatically opens the selected file.
Syntax
Public Function SelectAndOpenFile() As LongReturn Value
Returns ShellExecute result.
Example
Dim dlg As New cDialog
dlg.DialogTitle = "Select file to open"
dlg.AddFilter "Executable Files", "*.exe"
dlg.SelectAndOpenFile ' Auto open after selection📂 OpenFile Method
Description
Opens specified file using ShellExecute.
Syntax
Public Function OpenFile(ByVal strFilePath As String, Optional ByVal strOperation As String = "open") As LongParameters
| Parameter | Type | Description |
|---|---|---|
strFilePath | String | File path to open |
strOperation | String | Operation type, default "open" |
Example
Dim dlg As New cDialog
dlg.OpenFile "C:\Documents\file.txt" ' Open with default program
dlg.OpenFile "C:\Documents\file.txt", "edit" ' Open for editing➕ AddFilter Method
Description
Adds a file filter.
Syntax
Public Sub AddFilter(ByVal strDescription As String, ByVal strExtension As String)Parameters
| Parameter | Type | Description |
|---|---|---|
strDescription | String | Filter description |
strExtension | String | File extension pattern |
Example
dlg.AddFilter "Text Files", "*.txt"
dlg.AddFilter "Image Files", "*.jpg;*.png;*.gif"
dlg.AddFilter "All Files", "*.*"🧹 ClearFilter Method
Description
Clears all file filters.
Syntax
Public Sub ClearFilter()Example
dlg.ClearFilter ' Clear previous filters
dlg.AddFilter "New Type", "*.new"📋 Preset Filter Methods
SetCommonFilters
Sets common file filters (text files, all files).
dlg.SetCommonFiltersSetImageFilters
Sets image file filters.
dlg.SetImageFilters ' Contains bmp, jpg, png, gif, etc.SetDocumentFilters
Sets document file filters.
dlg.SetDocumentFilters ' Contains doc, xls, ppt, pdf, etc.SetCodeFilters
Sets code file filters.
dlg.SetCodeFilters ' Contains bas, c, cs, java, py, js, etc.🔧 File Path Utility Methods
GetFilePath
Gets the directory path of a file.
Dim path As String
path = dlg.GetFilePath("C:\Folder\file.txt") ' Returns "C:\Folder"GetFileName
Gets filename (with extension).
Dim name As String
name = dlg.GetFileName("C:\Folder\file.txt") ' Returns "file.txt"GetFileExtension
Gets file extension (with dot).
Dim ext As String
ext = dlg.GetFileExtension("C:\Folder\file.txt") ' Returns ".txt"GetFileNameWithoutExt
Gets filename (without extension).
Dim name As String
name = dlg.GetFileNameWithoutExt("C:\Folder\file.txt") ' Returns "file"🔄 Reset Method
Description
Resets all settings to default values.
Syntax
Public Sub Reset()Example
dlg.Reset ' Clear all settings, restore initial stateLast Updated: 2026-05-17