第1个回答 2020-05-23
Sub 选择文件夹()
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker) '运行后出现标准的选择文件夹对话框
If .Show Then myPath = .SelectedItems(1) Else Exit Sub '如选中则返回=-1 / 取消未选则返回=0
End With
If Right(myPath, 1) <> "" Then myPath = myPath & ""
'返回的是选中目标文件夹的绝对路径,但除了本地C盘、D盘会以"C:"形式返回外,其余路径无""需要自己添加
Getfd (myPath)
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal pth)
Dim Fn$, N%
Fn = Dir(pth & "\*.*")
While Fn <> ""
N = N + 1
Range("A" & N) = Fn
Fn = Dir
Wend
End Sub