SOLVED

format change in graph

Copper Contributor

I would like to change the format of all my graphs, for example change the type from Calibri 10 to Arial 12 in all the graphs of my Excel book, Does any know if it is possible?

4 Replies

@Javier_Fel91 

Change the chart text font

To change the text font for any chart element, such as a title or axis, right–click the element, and then click Font. When the Font box appears make the changes you want. Here’s an example—suppose you want to change the font size of the chart title.

 

or with VBA code

 

Sub testfont()
Dim myD As ChartObject
For Each myD In ActiveSheet.ChartObjects
    myD.Activate
    With Selection.Font
        .Name = "Arial"
        .Size = 12
    End With
Next
End Sub

 

 

Hope I was able to help you with this information.

 

NikolinoDE

I know I don't know anything (Socrates)

Hi!

Thanks for your reply. But I don't want to change just one chart. I want to change the font of all my charts (around 200 charts) and I do not want to do it one by one.
I guess I may do it in the VBA??
best response confirmed by Javier_Fel91 (Copper Contributor)
Solution

@Javier_Fel91 

Why doesn't it work with the previously sent VBA code?

It is for all diagrams in the active worksheet.

Anyway here is some additional code from Internet, untested.

 

Sub LoopThroughCharts()
'PURPOSE: Loop through every graph in the active workbook
'SOURCE: www.TheSpreadsheetGuru.com/The-Code-Vault
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Application.ScreenUpdating = False
Application.EnableEvents = False
Set CurrentSheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
  For Each cht In sht.ChartObjects
    cht.Activate
    
    'Do something with the chart...
     
 With cht.Chart.ChartArea.Format.TextFrame2.TextRange.Font
    .Name = "Arial"
    .Size = 12
End With
  
  
  Next cht
Next sht
CurrentSheet.Activate
Application.EnableEvents = True
End Sub

 

 

NikolinoDE

I know I don't know anything (Socrates)

 

@NikolinoDE Thanks! now it works,

 

before there was a mistake error "the object does not support this property or method"

 

Best regards!

1 best response

Accepted Solutions
best response confirmed by Javier_Fel91 (Copper Contributor)
Solution

@Javier_Fel91 

Why doesn't it work with the previously sent VBA code?

It is for all diagrams in the active worksheet.

Anyway here is some additional code from Internet, untested.

 

Sub LoopThroughCharts()
'PURPOSE: Loop through every graph in the active workbook
'SOURCE: www.TheSpreadsheetGuru.com/The-Code-Vault
Dim sht As Worksheet
Dim CurrentSheet As Worksheet
Dim cht As ChartObject
Application.ScreenUpdating = False
Application.EnableEvents = False
Set CurrentSheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
  For Each cht In sht.ChartObjects
    cht.Activate
    
    'Do something with the chart...
     
 With cht.Chart.ChartArea.Format.TextFrame2.TextRange.Font
    .Name = "Arial"
    .Size = 12
End With
  
  
  Next cht
Next sht
CurrentSheet.Activate
Application.EnableEvents = True
End Sub

 

 

NikolinoDE

I know I don't know anything (Socrates)

 

View solution in original post