有谁知道文件夹选择器的语法? [英] Does anyone know the syntax for the folder picker?
问题描述
这是我发现的,但它不太起作用:
This is what I have found, but it doesn't quite work:
函数GetFolder(ByVal title As String)As String
Dim vSelected As Variant
Dim fd As FileDialog
Dim s As String
Function GetFolder(ByVal title As String) As String
Dim vSelected As Variant
Dim fd As FileDialog
Dim s As String
GetFolder =""
设置fd = Application.FileDialog(msoFileDialogFolderPicker)
使用fd为
.AllowMultiSelect = False
.title = title
如果.Show = -1则为
对于每个vSelected In .SelectedItems
GetFolder = vSelected
下一个v选择
结束如果
结束与
设置fd =无
GetFolder = ""
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.AllowMultiSelect = False
.title = title
If .Show = -1 Then
For Each vSelected In .SelectedItems
GetFolder = vSelected
Next vSelected
End If
End With
Set fd = Nothing
结束功能
此代码打开文件夹选择器,但是当我点击文件夹时,它不会填充"文件夹名称:"。窗口底部的文本框,让我无法真正选择文件夹。
This code opens the folder picker, but when I click on a folder it does not populate the "Folder Name:" text box at the bottom of the window, leaving me unable to actually pick a folder.
非常欢迎所有建议。 -Fred
All suggestions greatfully welcomed. -Fred
推荐答案
我的代码在我尝试时运行正常。由于文件夹选择器对话框的AllowMultiSelect不能为True,因此您可以将代码简化为
Your code works fine when I try it. Since AllowMultiSelect cannot be True for the folder picker dialog, you can simplify the code to
Function GetFolder(ByVal Title As String) As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = Title
If .Show Then
GetFolder = .SelectedItems(1)
End If
End With
End Function
这篇关于有谁知道文件夹选择器的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!