“用户定义的类型未定义”用于简单的自定义类型

时间:2021-10-03 12:59:34

In Excel 2007 I have the following very simple code in VBA:

在Excel 2007中,我在VBA中有以下非常简单的代码:

Public Type specType
    sb As Long
End Type


Private Sub MyButton_Click()
    Dim spec As specType

    '...
End Sub

When the button is clicked, i get a "User-defined type not defined" Error on the "Dim spec As specType" line... why? Do I have to move my user defined types to a special location?

单击该按钮时,我在“Dim spec As SpecType”行中得到“用户定义的类型未定义”错误...为什么?我是否必须将用户定义的类型移动到特殊位置?

1 个解决方案

#1


11  

Turns out Types have to be defined before any functions in the module, otherwise they simply won't be recognized (without giving you an error).

结果必须在模块中的任何函数之前定义类型,否则它们将无法被识别(没有给出错误)。

#1


11  

Turns out Types have to be defined before any functions in the module, otherwise they simply won't be recognized (without giving you an error).

结果必须在模块中的任何函数之前定义类型,否则它们将无法被识别(没有给出错误)。