2014-12-01 6 views
4

Chars에는 ChartType as XlChartType 속성이 있지만 열거 형 값의 긴 목록입니다. 차트에 스택 된 시리즈를 모두 나열하지 않고 테스트하는 방법을 테스트 할 수 있습니까?Excel의 차트에 계열이 겹치지 않았는지 테스트 할 수있는 방법이 있습니까?

나는 시나리오 다음 피하기 위해 노력하고 아래

Select ActiveChart.ChartType 
    Case xlAreaStacked 
     .... 
    Case xlBarStacked 
     .... 
    Case xlColumnStacked 
     .... 
    ... 1000 more Cases .... 
End Select 
+1

그냥 사소한 nitpick 그럴 수 이상의 목록 모든 차트 유형을 한 줄에, 예를 들어, 'Case xlAreaStacked, xlBarStacked, xlColumnStacked'하지만 여전히 좋은 질문이라고 생각하며 누군가가 대답을 해줄 수 있기를 바랍니다. – Aiken

+0

글쎄 ... 이것은 정말로 개선 된 부분이므로 입력 @Aiken에 감사드립니다. – sgp667

답변

1

일부 샘플 코드는 요청 열거의 멤버들과 사전 객체를 생성 할 수 있습니다.

코드는 여기 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 
관련 문제