VBA- 弹出对话框,选择文件夹,并获取文件夹路径

时间:2025-02-07 14:44:11
Sub SelectFolder() Dim Path As String With Application.FileDialog(msoFileDialogFolderPicker) If .Show = -1 Then 'FileDialog 对象的 Show 方法显示对话框,并且返回 -1(如果按 OK)和 0(如果按 Cancel) Path = .SelectedItems(1) MsgBox "您选择的文件夹是:" & Path, vbOKOnly + vbInformation, "智能Excel" '获取到的Path长这个样子:"D:\VBA\Report\Format",Format就是我选中的文件夹的名字 End If End With End Sub