标题: 请教打开文件对话框指定格式筛选 [打印本页] 作者: accesscx 时间: 2010-12-2 16:54 标题: 请教打开文件对话框指定格式筛选 Function GetFileName(TitleText As String, Filter As String, FilterText As String, ByVal DialogType As Integer, Optional ByVal FilePath) As String
'参数DialogType说明:
'1.“打开”对话框
'2.“另存为”对话框(这个项不好用,所以加了出错处理为 Resume Next)
'3.“文件选取器”对话框
'4.“文件夹选取器”对话框
'例:AA = GetFileName("打开", "*.ini;*.txt", "配置文件", 1)
On Error Resume Next
Dim dlgOpen As FileDialog
Set dlgOpen = Application.FileDialog(DialogType)
With dlgOpen
.title = TitleText
.Filters.Clear
.Filters.ADD FilterText, Filter
.AllowMultiSelect = False
If IsMissing(FilePath) Then
.InitialFileName = a(10)
Else
.InitialFileName = FilePath
End If
.Show
End With
If dlgOpen.SelectedItems.Count > 0 Then
GetFileName = dlgOpen.SelectedItems(1)
Else
GetFileName = ""
End If
Set dlgOpen = Nothing