1

以下简单示例不起作用:

Public Type MyType
    a As Double
    b As Integer
End Type

Function Test() As Variant
    Dim x As MyType
    Test = 2
End Function

编译错误:未定义用户定义类型

我如何“定义”类型?

4

1 回答 1

1

你的代码在我的 excel 2010 中编译得很好

无论如何,利用用户定义的类型是没有用的

下面是一个“完整”的例子

Option Explicit

Public Type MyType
    a As Double
    b As Integer
End Type

Sub main()
    Dim x As MyType

    'initialize fields of your type
    x.a = 1.2
    x.b = 1

    MsgBox Test(x)
End Sub


Function Test(x As MyType) As Variant

    Test = x.a + x.b

End Function
于 2016-04-16T14:06:48.117 回答