VBA Excel:编译错误:需要对象吗?

发布于 2024-12-09 18:05:27 字数 447 浏览 0 评论 0原文

我在标记行中收到 VBA Excel“编译器错误:需要对象”错误。 我不明白原因。

顺便说一句:希望 Excel 支持 .Net 语言而无需包装器。

Option Explicit

Public Type Inherit
    ReqId As Integer
    Parent As Integer
    Depth As Integer
    Path As String
End Type

Sub test()
    Dim MyStructure() As Inherit
    ReDim MyStructure(1 To 1000)

    MyStructure(1).ReqId = 1

    Dim Data, refData As Inherit
    Set Data = MyStructure(1)  ' <---! 
    Beep

End Sub

I get a VBA Excel 'Compiler Error: Object required'-Error in the marked line.
I do not understand the reason.

BTW: Wish Excel would support a .Net language without wrapper needs.

Option Explicit

Public Type Inherit
    ReqId As Integer
    Parent As Integer
    Depth As Integer
    Path As String
End Type

Sub test()
    Dim MyStructure() As Inherit
    ReDim MyStructure(1 To 1000)

    MyStructure(1).ReqId = 1

    Dim Data, refData As Inherit
    Set Data = MyStructure(1)  ' <---! 
    Beep

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梓梦 2024-12-16 18:05:27

Set 用于对象的赋值,用户定义的类型被视为常规变量,因此使用 = 进行赋值。

另外(令人困惑); Dim Data, refData As Inherit 仅声明 Inherit 类型的 refData,必须在一行上声明它们; 将数据设为继承,refData 作为继承

Set is for the assignment of objects, a user defined type is treated like a regular variable so use = to assign.

Also (confusingly); Dim Data, refData As Inherit only declares refData of type Inherit to declare them both on one line you must; Dim Data As Inherit, refData As Inherit

爱的十字路口 2024-12-16 18:05:27
Dim Data, refData As Inherit

Data 声明为 Variant,仅将 refData 声明为 Inherit

Dim Data As Inherit, refData As Inherit

做你想做的事。 VBA语法在这里不是“常识”,我已经看到这个错误几十次了。编辑:当然,您必须在分配中省略 Set ,因为 Inherit 是用户定义的类型。

如果您正在寻找免费且易于使用的 Excel .NET 集成,请查看 Excel-DNA:

http://exceldna .codeplex.com/

Dim Data, refData As Inherit

declares Data as Variant, only refData as Inherit.

Dim Data As Inherit, refData As Inherit

does what you want. The VBA syntax is not "common sense" here, I have seen this error dozens of times. EDIT: of course, you will have to leave out Set in the assignment, since Inherit is a user defined type.

If you are looking for a free and easy to use .NET integration for Excel, look at Excel-DNA:

http://exceldna.codeplex.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文