VBA - 未定义用户定义的类型 [英] VBA - User-defined type not defined

查看:85
本文介绍了VBA - 未定义用户定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新 VBA 模块以使用 System.Windows.Forms.FolderBrowserDialog 类.我声明了我的对象如下:

I am trying to update an VBA module to use the System.Windows.Forms.FolderBrowserDialog class. I declared my object as follows:

Dim MyFolderBrowser As New System.Windows.Forms.FolderBrowserDialog

运行这个给了我错误未定义用户定义的类型.我认为编译器不知道该类,所以我尝试转到 Tools >References 并添加 Systems_Windows_Forms,但我仍然遇到相同的错误.有谁知道我在这里想念什么?我的代码中是否也需要对库的引用?

Running this gave me the error User-defined type not defined. I figured the compiler didn't know about that class so I tried going to Tools > References and adding Systems_Windows_Forms, but I'm still getting the same error. Does anyone know what I'm missing here? Do I need a reference to the library in my code as well?

推荐答案

System.Windows.Forms.FolderBrowserDialog 对我来说看起来像是来自 .Net 的东西,而不是 VBA.

System.Windows.Forms.FolderBrowserDialog looks like something from .Net to me, not VBA.

您可以在 Access VBA 中使用 Application.FileDialog.此示例使用后期绑定并允许用户从浏览对话框中选择文件夹.

You can use Application.FileDialog in Access VBA. This sample uses late binding and allows the user to select a folder from a browse dialog.

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 [版本] 对象库的引用.然后你可以像这样声明对象......

If you prefer to use early binding, set a reference to the Microsoft Office [version] Object Library. You could then declare the object like this ...

Dim objFileDialog As FileDialog

并且您不需要定义常量,因此如果使用早期绑定,请丢弃此行...

And you wouldn't need to define the constant, so discard this line if using early binding ...

Const msoFileDialogFolderPicker As Long = 4

这篇关于VBA - 未定义用户定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆