Skip to content

Instantly share code, notes, and snippets.

@tsycho
Created September 1, 2011 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsycho/1186360 to your computer and use it in GitHub Desktop.
Save tsycho/1186360 to your computer and use it in GitHub Desktop.
Format all charts in FIMS style
Sub formatChartInFimsStyle()
Dim myChart As Chart
Set myChart = ActiveChart
' Set width and height
myChart.ChartArea.Height = 158
myChart.ChartArea.Width = 230
myChart.ChartArea.Format.Line.Visible = msoFalse
' Format chart axes
For Each ax In myChart.Axes
ax.TickLabels.Font.Name = "Arial Narrow"
ax.TickLabels.Font.Size = 8
If ax.HasTitle Then
ax.AxisTitle.Font.Name = "Arial Narrow"
ax.AxisTitle.Font.Size = 8
End If
Next ax
' Format chart legend
If myChart.HasLegend Then
myChart.Legend.Font.Name = "Arial Narrow"
myChart.Legend.Font.Size = 8
myChart.Legend.Position = xlTop
myChart.Legend.Width = 200
myChart.Legend.Left = 15
End If
' Format y-axis gridlines
Set ax = myChart.Axes(xlValue)
With ax
.HasMinorGridlines = False
.HasMajorGridlines = True
.MajorGridlines.Border.LineStyle = xlDash
.MajorGridlines.Border.Color = RGB(210, 210, 210) 'light gray
End With
' Format chart series
Call formatSeries(myChart)
End Sub
Sub formatAllCharts()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Select
For i = 1 To ActiveSheet.ChartObjects.Count
ActiveSheet.ChartObjects(i).Select
Call formatChartInFimsStyle
Next i
Next ws
End Sub
Sub formatSeries(ByRef myChart As Chart)
Dim colors(1 To 6) As Long
Dim lineStyles(1 To 6) As Integer
Dim i As Integer
colors(1) = RGB(0, 0, 0)
colors(2) = RGB(120, 120, 120)
colors(3) = colors(1)
colors(4) = colors(2)
colors(5) = RGB(110, 110, 255)
colors(6) = colors(5)
lineStyles(1) = xlContinuous
lineStyles(2) = xlContinuous
lineStyles(3) = xlDash
lineStyles(4) = xlDash
lineStyles(5) = xlContinuous
lineStyles(6) = xlDash
i = 1
For Each ss In myChart.SeriesCollection
ss.Border.LineStyle = lineStyles(i)
ss.Format.Line.ForeColor.RGB = colors(i)
ss.Format.Line.Weight = 2
i = i + 1
Next ss
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment