Gar*_*ent 2 excel vba enumeration excel-vba
我试图在工作表中创建一些简单的表,提供常见枚举的数字等效,如:
此示例适用于Border枚举变量.这个材料可以在MSDN中闲逛找到,但是当我不在线时我经常需要工作,这种类型的"帮助"不可用.
我目前正在用两个独立的循环填充我的小桌子:
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
Run Code Online (Sandbox Code Playgroud)
我真的想避免保留两个独立的数组; 一个用于文本字符串,另一个用于枚举.
有没有办法从文本字符串中获取枚举,或者将枚举转换为文本字符串?
任何建议将不胜感激.
我不相信你需要以编程方式生成这样的列表才能创建它.Microsoft在MSDN中提供了所有这些的定义:
https://msdn.microsoft.com/en-us/vba/excel-vba/articles/constants-enumeration-excel
您可以从那里下载并将其粘贴到电子表格中.您甚至可以通过Web查询使其动态化,以便您可以随时了解任何更改.这是一个宏,它做到了这一点:
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$1")).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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
297 次 |
| 最近记录: |