特定于VBA:
是否可以要求用户通过标准的Windows“浏览”选项指定目录名称,并将其作为变量读取(而不是在软件中进行硬编码)。
如:
String MyStr = <Inputted full path by the user via the Windows Browse Selection>
最佳答案
这是您可以用来允许用户浏览文件夹的功能:
Public Function pickFolder() As String
Dim strSelectedItem As String
Dim dlgPickFolder As FileDialog
Set dlgPickFolder = Application.FileDialog(msoFileDialogFolderPicker)
With dlgPickFolder
.AllowMultiSelect = False
End With
If dlgPickFolder.Show = -1 Then
strSelectedItem = dlgPickFolder.SelectedItems(1) & "\"
Else
strSelectedItem = ""
Set fd = Nothing
End If
Set fd = Nothing
pickFolder = strSelectedItem
End Function
您可以通过使用此函数设置所需变量的值来简单地使用它:
Dim sFolder As String
sFolder = pickFolder()
请让我们知道是否有帮助,谢谢