-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEXCEL_CHART_LABELS_LIBR.bas
executable file
·166 lines (135 loc) · 5.38 KB
/
EXCEL_CHART_LABELS_LIBR.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Attribute VB_Name = "EXCEL_CHART_LABELS_LIBR"
'--------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------
Option Explicit 'Requires that all variables to be declared explicitly.
Option Base 1 'The "Option Base" statement allows to specify 0 or 1 as the
'default first index of arrays.
'--------------------------------------------------------------------------------------------------------
'--------------------------------------------------------------------------------------------------------
'************************************************************************************
'************************************************************************************
'FUNCTION : EXCEL_CHART_APPLY_DATA_LABELS_FUNC
'DESCRIPTION :
'LIBRARY : EXCEL_CHART
'GROUP :
'ID :
'AUTHOR : RAFAEL NICOLAS FERMIN COTA
'************************************************************************************
'************************************************************************************
Function EXCEL_CHART_APPLY_DATA_LABELS_FUNC(ByRef SERIE_OBJ As Excel.Series, _
ByRef NAMES_ARR As Variant)
'Call EXCEL_CHART_APPLY_DATA_LABELS_FUNC(ActiveSheet.ChartObjects("Chart 7").Chart.SeriesCollection(1), _
'Array("TD", "KA"))
Dim i As Long
Dim j As Long
On Error GoTo ERROR_LABEL
EXCEL_CHART_APPLY_DATA_LABELS_FUNC = False
SERIE_OBJ.ApplyDataLabels Type:=xlDataLabelsShowValue, AutoText:=True, _
LegendKey:=False
'SERIE_OBJ.ApplyDataLabels AutoText:=True, LegendKey:=False, _
HasLeaderLines:=False, ShowSeriesName:=True, ShowCategoryName:=False, _
ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False, Separator:=" "
j = 1
For i = LBound(NAMES_ARR) To UBound(NAMES_ARR)
SERIE_OBJ.Points(j).DataLabel.Characters.Text = NAMES_ARR(i)
j = j + 1
Next i
With SERIE_OBJ.DataLabels.Font
.name = "Helvetica-Narrow"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
EXCEL_CHART_APPLY_DATA_LABELS_FUNC = True
Exit Function
ERROR_LABEL:
EXCEL_CHART_APPLY_DATA_LABELS_FUNC = False
End Function
'************************************************************************************
'************************************************************************************
'FUNCTION : EXCEL_CHART_INSERT_DATA_LABELS_FUNC
'DESCRIPTION :
'LIBRARY : EXCEL_CHART
'GROUP :
'ID : 001
'AUTHOR : RAFAEL NICOLAS FERMIN COTA
'************************************************************************************
'************************************************************************************
'The comparable chart with labels for each series shown on right.
'Debug.Print EXCEL_CHART_INSERT_DATA_LABELS_FUNC(ActiveChart)
Function EXCEL_CHART_INSERT_DATA_LABELS_FUNC(ByRef CHART_OBJ As Excel.Chart)
Dim i As Long
Dim SRC_SERIES As Excel.Series
On Error GoTo ERROR_LABEL
EXCEL_CHART_INSERT_DATA_LABELS_FUNC = False
For Each SRC_SERIES In CHART_OBJ.SeriesCollection
With SRC_SERIES
i = .Points.COUNT
SRC_SERIES.Points(i).ApplyDataLabels Type:=xlDataLabelsShowValue, _
AutoText:=True, LegendKey:=False
SRC_SERIES.Points(i).DataLabel.Text = SRC_SERIES.name
' MsgBox (SRC_SERIES.Name)
With SRC_SERIES.DataLabels
.AutoScaleFont = True
With .Font
.name = "Arial"
.FontStyle = "Bold"
.Size = 8
End With
With .Border
.WEIGHT = xlHairline
.LineStyle = xlNone
End With
.Shadow = False
With .Interior
.ColorIndex = 2
.PatternColorIndex = 1
.Pattern = xlSolid
End With
End With
End With
Next SRC_SERIES
EXCEL_CHART_INSERT_DATA_LABELS_FUNC = True
Exit Function
ERROR_LABEL:
EXCEL_CHART_INSERT_DATA_LABELS_FUNC = False
End Function
'************************************************************************************
'************************************************************************************
'FUNCTION : EXCEL_CHART_OFFSET_DATA_LABELS_FUNC
'DESCRIPTION :
'LIBRARY : EXCEL_CHART
'GROUP :
'ID : 001
'AUTHOR : RAFAEL NICOLAS FERMIN COTA
'************************************************************************************
'************************************************************************************
Function EXCEL_CHART_OFFSET_DATA_LABELS_FUNC(ByRef DATA_ARR As Variant, _
ByRef CHART_OBJ As Excel.Chart)
Dim i As Long
Dim j As Long '1
Dim LEFT_VAL As Double '400
Dim SERIES_OBJ As Excel.Series
On Error GoTo ERROR_LABEL
EXCEL_CHART_OFFSET_DATA_LABELS_FUNC = True
For Each SERIES_OBJ In CHART_OBJ.SeriesCollection
For i = LBound(DATA_ARR) To UBound(DATA_ARR)
j = DATA_ARR(i, 1)
LEFT_VAL = DATA_ARR(i, 2)
With SERIES_OBJ.Points(j).DataLabel
.Left = LEFT_VAL
End With
Next i
Next SERIES_OBJ
EXCEL_CHART_OFFSET_DATA_LABELS_FUNC = True
Exit Function
ERROR_LABEL:
EXCEL_CHART_OFFSET_DATA_LABELS_FUNC = False
End Function