Excel,Visual Basic编辑器,枚举类型声明 - 未定义用户定义的类型

时间:2021-12-23 16:33:08

I have the following code and I don't know why Excel doesn't see the Enum type (that I've declared) in the Test2() subroutine:

我有以下代码,我不知道为什么Excel没有在Test2()子例程中看到Enum类型(我已声明):

Private Sub Test1()
    Dim test_name As Variant

End Sub


Private Enum rlcRollercoasterState
    rlcRollercoasterDisabled
    rlcRollercoasterEnabled
    rlcRollercoasterBroken
    rlcRollercoasterMissing
End Enum


Private Sub Test2()
    Dim var1 As Variant

    Dim rlcRC1State As rlcRollercoasterState ' User-defined type not defined

End Sub

If I copy the Test1() subroutine after the Enum type declaration, Excel recognizes the rlcRollercoasterState type in Test1(). If I comment out the Test1() subroutine, Excel recognizes rlcRollercoasterState type in Test2().

如果我在枚举类型声明后复制Test1()子例程,Excel将识别Test1()中的rlcRollercoasterState类型。如果我注释掉Test1()子例程,Excel会识别Test2()中的rlcRollercoasterState类型。

Why does the Excel fail to see the rlcRollercoasterState type in the Test2() subroutine?

为什么Excel无法在Test2()子例程中看到rlcRollercoasterState类型?

1 个解决方案

#1


9  

Excel,Visual Basic编辑器,枚举类型声明 - 未定义用户定义的类型

Always "Debug/Compile VBAProject" (Alt-dl) before running the code. As in your example it give the error. The compile error says it wants the declaration statement at the beginning of the module.

在运行代码之前始终“调试/编译VBAProject”(Alt-dl)。在您的示例中,它给出了错误。编译错误说它需要模块开头的声明语句。

#1


9  

Excel,Visual Basic编辑器,枚举类型声明 - 未定义用户定义的类型

Always "Debug/Compile VBAProject" (Alt-dl) before running the code. As in your example it give the error. The compile error says it wants the declaration statement at the beginning of the module.

在运行代码之前始终“调试/编译VBAProject”(Alt-dl)。在您的示例中,它给出了错误。编译错误说它需要模块开头的声明语句。