-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlotStyling.bas
136 lines (115 loc) · 4.02 KB
/
PlotStyling.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
Attribute VB_Name = "PlotStyling"
Option Explicit
Sub StylePlot()
'
'
Dim i As Integer
Dim n As Integer
Dim lineStyle As Variant
Dim val As Double
Dim obj As Object
On Error Resume Next
Selection.Format.Line.Visible = msoFalse
With ActiveChart.Parent
.Height = 210 ' resize
.Width = 230 ' resize
'.Top = 150 ' reposition
'.Left = 400 ' reposition
End With
lineStyle = Array(msoLineSolid, msoLineSysDash, msoLineSysDashDot, msoLineSysDot, msoLineDash, msoLineLongDashDot, msoLineDashDotDot, msoLineDashDot, msoLineLongDashDotDot)
Application.CommandBars("Format Object").Visible = False
For i = 1 To ActiveChart.FullSeriesCollection.Count
ActiveChart.FullSeriesCollection(i).Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.DashStyle = lineStyle(i)
End With
Next i
'Formatting Axes
With ActiveChart
.HasTitle = False
'X axis name
If .Axes(xlCategory, xlPrimary).HasTitle = False Then
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X-Axis"
End If
If .Axes(xlValue, xlPrimary).HasTitle = False Then
'y-axis name
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y-Axis"
End If
End With
'Formatting x-axis
With ActiveChart.Axes(xlCategory, xlPrimary).AxisTitle.Font
.Name = "Times New Roman"
.Size = 8
.Color = msoThemeColorText2
End With
With ActiveChart.Axes(xlCategory).TickLabels.Font
.Name = "Times New Roman"
.Size = 8
.Color = msoThemeColorText2
End With
'formatting y-axis
With ActiveChart.Axes(xlValue, xlPrimary).AxisTitle.Font
.Name = "Times New Roman"
.Size = 8
.Color = msoThemeColorText2
End With
With ActiveChart.Axes(xlValue, xlPrimary).TickLabels.Font
.Name = "Times New Roman"
.Size = 8
.Color = msoThemeColorText2
End With
With ActiveChart.ChartArea.Format.TextFrame2.TextRange.Font
.Name = "Times New Roman"
.Size = 8
.Fill.ForeColor.ObjectThemeColor = msoThemeColorText1
End With
ActiveChart.Legend.Position = xlBottom
'Remove Gridlines
ActiveChart.Axes(xlValue).MajorGridlines.Delete
ActiveChart.Axes(xlCategory).MajorGridlines.Delete
'Add tickmarks inside
ActiveChart.Axes(xlValue).MajorTickMark = xlInside
ActiveChart.Axes(xlCategory).MajorTickMark = xlInside
'plotarea border
With ActiveChart.PlotArea.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.Brightness = 0
.Transparency = 0
End With
With ActiveChart.Axes(xlValue).Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
With ActiveChart.Axes(xlCategory).Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
End Sub
Sub SetColorSeries()
Dim val As Double
Dim obj As Object
val = 1#
For Each obj In ActiveChart.FullSeriesCollection
val = val / 2
With obj.Format.Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorText1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = val
.Solid
End With
Next
End Sub