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

Flo*_*ann 7 excel vba excel-vba user-defined-types

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

Public Type specType
    sb As Long
End Type


Private Sub MyButton_Click()
    Dim spec As specType

    '...
End Sub
Run Code Online (Sandbox Code Playgroud)

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

Flo*_*ann 12

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