vba 获取 msoFileDialogFolderPicker 的初始路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26717371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 05:06:59  来源:igfitidea点击:

Getting the initial path of msoFileDialogFolderPicker

vbaexcel-vbaexcel

提问by Smittey

The application I am working on requires the users to select a folder using msoFileDialogFolderPicker, and it rather usefully opens the folder picker in the last location. However, our users occasionally change a folder name in the path. This causes a windows 'location unavailable' dialog box. This scares our users as they don't know what's happening.

我正在开发的应用程序要求用户使用 msoFileDialogFolderPicker 选择一个文件夹,它在最后一个位置打开文件夹选择器非常有用。但是,我们的用户偶尔会更改路径中的文件夹名称。这会导致 Windows 的“位置不可用”对话框。这让我们的用户感到害怕,因为他们不知道发生了什么。

My question is, how do I find out what the initial folder location is going to be? I can then trap for it just set it to a default location instead.

我的问题是,如何找出初始文件夹位置?然后我可以为它设置陷阱,只需将其设置为默认位置即可。

My code very simply is

我的代码很简单

GetFolder As String
Set folder = Application.FileDialog(msoFileDialogFolderPicker)

With folder
    .Title = "Please Select a Folder"
    .InitialFileName = "C:\"
    .AllowMultiSelect = False

    If .Show <> -1  Then Goto EndSub
    GetFolder = .SelectedItems(1)
End With

Thanks

谢谢

采纳答案by Gary's Student

Consider:

考虑:

Sub qwerty()
    Dim fldr As FileDialog
    Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
    MsgBox fldr.InitialFileName
End Sub