Hello All!
I have made myself a handy little tool for formatting charts and everything works just fine, except formatting the text for chart titles. I have looked at other solutions, and it seems I should have it correct, but still I get Error 424, "Object Required". What gives?
Code underneath, problem line stated in red. The problem seems to be related to using ".Font", but that should be correct.
Option Explicit
Sub ChartFont()
' Setting dimensions
Dim TitleCopy, SeriesCopy, AxesCopy As String
Dim TitleSize, SeriesSize, AxesSize As Integer
Dim sht As Worksheet
Dim CurrentSheet, Dimsheet As Worksheet
Dim cht As ChartObject
Dim SeriesBold, TitleBold, AxesBold As Boolean
'Efficiency settings while running
Application.ScreenUpdating = False
Application.EnableEvents = False
' Setting the sheet names used
Set Dimsheet = ActiveWorkbook.Sheets(1)
Set CurrentSheet = ActiveSheet
TitleCopy = Dimsheet.Cells(3, 2).Font.Name 'Defining the Title font
TitleSize = Dimsheet.Cells(3, 2).Font.Size 'Defining the Title font size
TitleBold = Dimsheet.Cells(3, 2).Font.Bold 'Defining the Title font bold or not
SeriesCopy = Dimsheet.Cells(4, 2).Font.Name 'Defining the Legend font
SeriesSize = Dimsheet.Cells(4, 2).Font.Size 'Defining the Legend font size
SeriesBold = Dimsheet.Cells(4, 2).Font.Bold 'Defining the Legend font bold or not
AxesCopy = Dimsheet.Cells(5, 2).Font.Name 'Defining the Axes font
AxesSize = Dimsheet.Cells(5, 2).Font.Size 'Defining the Axes font size
AxesBold = Dimsheet.Cells(5, 2).Font.Bold 'Defining the Axes font bold or not
'Dimsheet.Cells(3, 3) = TitleCopy 'Test cells
'Dimsheet.Cells(3, 4) = TitleSize 'Test cells
' ----- Loop that goes through all charts in all sheets
For Each sht In ActiveWorkbook.Worksheets 'Loop through sheets in workbook
For Each cht In sht.ChartObjects 'Loop through all charts within sheet
cht.Activate 'Activates the sheet for changes
With ActiveChart.ChartTitle.Format.TextFrame2.TextRange.Font 'Font changer for chart titles
.Size = TitleSize
.Name = TitleCopy
.Bold = TitleBold
End With
With ActiveChart.Legend.Format.TextFrame2.TextRange.Font 'Font changer for chart legends
.Size = SeriesSize
.Name = SeriesCopy
.Bold = SeriesBold
End With
With ActiveChart.Axes(xlCategory).AxisTitle.Font 'Font changer for chart axis
.Size = AxesSize
.Name = AxesCopy
.Bold = AxesBold
End With
Next cht
Next sht
Dimsheet.Activate
Application.EnableEvents = True
End Sub
Bookmarks