获取枚举的等效文本

Getting The Text Equivalent of An Enumeration

我正在尝试在工作表中创建一些简单的 tables,以给出常见枚举的数字等价物,例如:

此示例适用于 Border 个枚举变量。这个material可以在MSDN转转找到,但是经常需要工作不在线,这种"help"是没有的

我目前正在用两个独立的循环填充我的小 table:

Sub trythisB()
    Dim i As Long
    i = 1
    For Each a In Array(xlInsideHorizontal, xlInsideVertical, xlEdgeLeft, xlEdgeRight, xlEdgeBottom, xlEdgeTop)
            Cells(i, 2) = a
            i = i + 1
    Next a
End Sub

Sub trythisA()
    Dim i As Long
    i = 1
    For Each a In Array("xlInsideHorizontal", "xlInsideVertical", "xlEdgeLeft", "xlEdgeRight", "xlEdgeBottom", "xlEdgeTop")
            Cells(i, 1) = a
            i = i + 1
    Next a
End Sub

我真的很想避免保留两个单独的数组;一个用于文本字符串,另一个用于枚举。

有没有办法从文本字符串中获取枚举,或者将枚举转换为文本字符串?

如有任何建议,我们将不胜感激。

我认为您不需要以编程方式生成这样的列表来创建它。 Microsoft 在 MSDN 中提供了所有这些的定义:

https://msdn.microsoft.com/en-us/vba/excel-vba/articles/constants-enumeration-excel

您可以从那里下载并粘贴到您的电子表格中。您甚至可以通过网络查询使其动态化,这样您就可以及时了解任何更改。这是一个执行此操作的宏:

Sub GetEnumerationDefinitions()

    ActiveWorkbook.Queries.Add Name:="Enumerations", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Source = Web.Page(Web.Contents(""https://msdn.microsoft.com/en-us/vba/excel-vba/articles/constants-enumeration-excel""))," & Chr(13) & "" & Chr(10) & "    Data0 = Source{0}[Data]," & Chr(13) & "" & Chr(10) & "    #""Changed Type"" = Table.TransformColumnTypes(Data0,{{""Name"", type text}, {""Value"", Int64.Type}, {""Description"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Changed Type"""
    ActiveWorkbook.Worksheets.Add
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Enumerations"";Extended Properties=""""" _
        , Destination:=Range("$A")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array("SELECT * FROM [Enumerations]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "Table_0"
        .Refresh BackgroundQuery:=False
    End With
End Sub