获取文件路径(以文件夹结尾) [英] Get File Path (ends with folder)
本文介绍了获取文件路径(以文件夹结尾)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道如何让用户单击按钮导航到要打开的特定文件.
I know how to let the user click on a button to navigate to a specific file to open.
代码:
Private Sub CommandButton2_Click()
Dim vaFiles As Variant
vaFiles = Application.GetOpenFilename()
ActiveSheet.Range("B9") = vaFiles
End Sub
我想要第二个按钮,它将允许用户导航到文件夹以保存程序创建的.pdf
文件.
I want a second button that will let the user navigate to a folder to save the .pdf
file that my program creates.
问题:GetOpenFilename
要求用户单击文件.如果文件夹中没有文件,那么用户将无能为力.
The problem: The GetOpenFilename
requires the user to click on a file. If there's no file in the folder then there's nothing the user can do.
推荐答案
使用Application.FileDialog
对象
Sub SelectFolder()
Dim diaFolder As FileDialog
Dim selected As Boolean
' Open the file dialog
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
selected = diaFolder.Show
If selected Then
MsgBox diaFolder.SelectedItems(1)
End If
Set diaFolder = Nothing
End Sub
这篇关于获取文件路径(以文件夹结尾)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文