|
你这个对话框得用API才能实现。
插入一个模块,代码放在模块中。- Private Type BROWSEINFO
- hOwner As Long
- pidlRoot As Long
- pszDisplayName As String
- lpszTitle As String
- ulFlags As Long
- lpfn As Long
- lParam As Long
- iImage As Long
- End Type
- Const BIF_RETURNONLYFSDIRS = &H1
- Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
- Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
- Function ChooseFolder(Optional strTitle As String = "请选择文件夹") As String
- Dim bi As BROWSEINFO
- Dim pidl As Long
- Dim strPath As String * 512
- Dim lResult As Long
- Dim iPos As Integer
- With bi
- .hOwner = 0&
- .pidlRoot = 0&
- .lpszTitle = strTitle
- .ulFlags = BIF_RETURNONLYFSDIRS
- End With
- pidl = SHBrowseForFolder(bi)
- strPath = Space$(512)
- lResult = SHGetPathFromIDList(ByVal pidl&, ByVal strPath)
- If lResult Then
- iPos = InStr(strPath, Chr$(0))
- ChooseFolder = Left(strPath, iPos - 1)
- End If
- End Function
- Sub Main()
- Dim strPath As String
- Dim strFilename As String
- Dim iCount As Integer
- Dim arrFilename(1 To 1024) As String
- strPath = ChooseFolder()
- If Len(strPath) = 0 Then
- MsgBox "没有选择文件夹" & vbCrLf & "点 确定 后代码结束", vbCritical + vbOKOnly
- Exit Sub
- End If
- If Not Right(strPath, 1) Like "" Then strPath = strPath & Application.PathSeparator
- strFilename = Dir(strPath & "*.xls")
- Do While Len(strFilename) > 0 And strFilename <> ThisWorkbook.Name
- Debug.Print strFilename
- iCount = iCount + 1
- arrFilename(iCount) = strPath & strFilename
- strFilename = Dir
- Loop
- '所有的完全文件名都在数组arrFilename中
-
- End Sub
复制代码 |
|