Is there a way to get the enums in VBA?

前端 未结 8 1953
南旧
南旧 2020-12-06 07:51

Is there a way to get the enums in VBA? Something like this example for C#, but for VBA?

using System;

class EnumsExampleZ
{
    private enum SiteNames
             


        
8条回答
  •  自闭症患者
    2020-12-06 08:44

    There is no built-in function, though it is easy enough to roll your own in a concrete case:

    Enum FruitType
        Apple = 1
        Orange = 2
        Plum = 3
    End Enum
    
    Function EnumName(i As Long) As String
        EnumName = Array("Apple","Orange","Plum")(i-1)
    End Function
    

    If you have several different enums, you could add a parameter which is the string name of the enum and Select Case on it.

    Having said all this, it might possible to do something with scripting the VBA editor, though it is unlikely to be worth it (IMHO).

提交回复
热议问题