代码如下:
Sub GetFile()Dim FolderPicker As Object
Dim FilePath As String
Set FolderPicker = Application.FileDialog(msoFileDialogFilePicker)
With FolderPicker
.Filters.Clear
.Filters.Add "文本文件", "*.txt"
If .Show = -1 Then
FilePath = .SelectedItems(1)
Else
Exit Sub
End If
End With
End Sub
'注意引用 microsoft office 10.0 (或以上) object library'在文件对话框对中返回选择一个文件夹的路径.Public Function ChooseFolder() As StringDim dlgOpen As FileDialogSet dlgOpen = Application.FileDialog(msoFileDialogFolderPicker)With dlgOpenIf .Show = -1 ThenChooseFolder = .SelectedItems(1)End IfEnd WithSet dlgOpen = NothingEnd Function'--------------------------------------------------------'在文件对话框对中,选择一个文件。Public Function ChooseOneFile(Optional TitleStr As String= 选择你要的文件, Optional TypesDec As String = 所有文件,Optional Exten As String = *.*) As StringDim dlgOpen As FileDialogSet dlgOpen = Application.FileDialog(msoFileDialogFilePicker)With dlgOpen.Title = TitleStr.Filters.Clear'清除所有的文件类型..Filters.Add TypesDec, Exten.AllowMultiSelect = False '不能多选.If .Show = -1 Then'.AllowMultiSelect = True '多个文件'For Each vrtSelectedItem In .SelectedItems'MsgBox Path name:& vrtSelectedItem'Next vrtSelectedItemChooseOneFile = .SelectedItems(1)'第一个文件End IfEnd With欢迎分享,转载请注明来源:内存溢出
评论列表(0条)