나는 사용자 정의 기능에 대한 예약을 표명했지만, 솔직히 오히려 실수 등. 어느 사용자 개입 또는 코드// 조작 삭제 될 수 있습니다 숨겨진 열보다, 내가 걸릴 경로 이해 실행.
이 서브 루틴은 Cells (2,2)에서 문자열 값을 가져 와서 아래 함수를 통해 전달하여 xlChartType으로 변환합니다. 여기
Sub ChartTypes()
Dim cht As Chart
Dim ws As Worksheet
Dim stringType As String
Dim chartType As XlChartType
Set ws = Sheets(1)
stringType = CStr(Cells(2, 2).Value)
'Use the function to return the correct xlChartType in the AddChart:
Set cht = ws.Shapes.AddChart(_
GetChartTypeConstant(stringType), _
50, 50, 300, 200).Chart
End Sub
그리고
는
Set cObj...
내에서 호출되는 함수입니다.
Private Function GetChartTypeConstant(myString As String) As XlChartType
'This function returns an xlCharType constant value from a descriptive string
' which you will need to define or modify for your needs;
' using select case also means you can use more descriptive/user-friendly
' names on your worksheet.
Select Case myString
Case "xlBarClustered", "Clustered Bars", "Horizontal Bars"
GetChartTypeConstant = xlBarClustered
Case "xlColumnClustered", "Clustered Columns", "Vertical Columns"
GetChartTypeConstant = xlColumnClustered
Case "xlLine", "Lines Only"
GetChartTypeConstant = xlLine
'Additional cases can be added for
' additional chart types.
End Select
End Function
에는 오류 -이없는주의 등, "xlBarClustered는"당신이 "수평 바"를 부를 수있는 대신, 선택 케이스 기능을 사용하여 더 많은 사용자에게 친숙한 이름을 사용할 수 있도록한다고합니다 하위 또는 기능 중 하나에서 처리.
안녕하세요, 초기 답변에 많은 감사하지만 혼란이 조금 있다고 생각합니다. "xlLine"은이 경우 사용자 이름이 아닙니다 (좋은 사용자 이름이 아닐 것이라는 것에 동의합니다). 사실 xlChartType의 열거 형 값입니다. 기본 선 차트를 나타냅니다. 그러나 나는 당신이 의미하는 것을 얻습니다 ... –
@ DarkLord_109 "사용자 이름"은 "사용자 이름"이 아니라 "사용자 이름"을 의미합니다. 나는 'xlLine'(4라는 숫자)의 수치를 셀에 넣고, 인접한 셀에 "Line chart"와 같은 것을 넣는다. 이 줄을 따라 – GSerg
을 참조하면 http://msdn.microsoft.com/en-us/library/bb241008 (v = office.12) .aspx XlChartType 용 – datatoo