|
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 = CurrentProject.Path
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
End Function
'说明:需要引用Microsoft Office 1X.0 Object Library (如果是2003,引用11.0,如果是2007,引用12.0,如果是2010,引用14.0)(2007与2010的引用需要单击"浏览"按钮指定的dll文件,以2010为例,dll文件是C:\Program Files\Common Files\microsoft shared\OFFICE14\MSO.DLL
|
评分
-
1
查看全部评分
-
|