我正在尝试更新VBA模块以使用System.Windows.Forms.FolderBrowserDialog
类。我宣布我的对象如下:
Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog
运行这个给了我错误User-defined type not defined
。我认为编译器不知道该类,所以我尝试去Tools > References
并添加Systems_Windows_Forms
,但我仍然得到同样的错误。有谁知道我在这里缺少什么?我的代码中是否还需要对库的引用?
答案 0 :(得分:3)
System.Windows.Forms.FolderBrowserDialog
看起来像是.Net
给我的东西,而不是VBA。
您可以在Access VBA中使用Application.FileDialog
。此示例使用后期绑定,并允许用户从浏览对话框中选择文件夹。
Const msoFileDialogFolderPicker As Long = 4
Dim objFileDialog As Object ' FileDialog
Set objFileDialog = Application.FileDialog(msoFileDialogFolderPicker)
With objFileDialog
.AllowMultiSelect = False
If .Show Then
Debug.Print .SelectedItems(1)
End If
End With
如果您更喜欢使用早期绑定,请设置对 Microsoft Office [版本]对象库的引用。然后你可以像这样声明对象......
Dim objFileDialog As FileDialog
并且您不需要定义常量,因此如果使用早期绑定则丢弃此行...
Const msoFileDialogFolderPicker As Long = 4