일부 샘플 코드는 요청 열거의 멤버들과 사전 객체를 생성 할 수 있습니다.
코드는 여기 dlmille의 대답에서 적응 : VBA의`Select..Case` 구문을, http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_27613392.html
Sub tester()
Dim dict
Set dict = GetEnumLookup("Excel", "XlChartType")
If Not dict Is Nothing Then
'get string from numeric value and see if it contains "stacked"
Debug.Print UCase(dict(XlChartType.xl3DAreaStacked)) Like "*STACKED*"
Debug.Print UCase(dict(XlChartType.xl3DArea)) Like "*STACKED*"
Else
MsgBox "Enum not recognised!"
End If
End Sub
'VB Project References required:
' Microsoft Visual Basic for Applications Extensibility
' TypeLib Information
Function GetEnumLookup(LibName As String, sEnumName As String) As Object
Dim rv As Object
Dim tl As TLI.TypeLibInfo
Dim mi As TLI.MemberInfo
Dim tiEnum As TLI.TypeInfo
Dim vbProj As VBProject, oVBProjRef As Reference
Set vbProj = ThisWorkbook.VBProject
For Each oVBProjRef In vbProj.References
'Debug.Print oVBProjRef.Name, oVBProjRef.FullPath
If oVBProjRef.Name = LibName Then
Set tl = New TypeLibInfo
tl.ContainingFile = oVBProjRef.FullPath
On Error Resume Next
Set tiEnum = tl.GetTypeInfo(sEnumName)
On Error GoTo 0
If Not tiEnum Is Nothing Then
Set rv = CreateObject("scripting.dictionary")
For Each mi In tiEnum.Members
rv.Add mi.Value, mi.Name
'or if you want to map the other direction...
'rv.Add mi.Name, mi.Value
Next mi
End If
Exit For
End If
Next oVBProjRef
Set GetEnumLookup = rv
End Function
그냥 사소한 nitpick 그럴 수 이상의 목록 모든 차트 유형을 한 줄에, 예를 들어, 'Case xlAreaStacked, xlBarStacked, xlColumnStacked'하지만 여전히 좋은 질문이라고 생각하며 누군가가 대답을 해줄 수 있기를 바랍니다. – Aiken
글쎄 ... 이것은 정말로 개선 된 부분이므로 입력 @Aiken에 감사드립니다. – sgp667