Question

If I have many charts in the file and I'd like to eventually export them all as images with VBA code. If charts are given no "chart titles", VBA will save charts under the "name box" name. The problem is, that if i have many charts and not al of them have sequential labels, I need to give that back in order. E.g., wanna have charts with names chart1, chart2, chart3,..

Is it possible with simple VBA to change the names for all of them at once? It's very time consuming to manualy change it for each of them, in case you have 100+ charts.

Regards, Gasper

Was it helpful?

Solution

You can access every chart of a sheet using the Shape.Chart property of a Sheet object.

To change the name of each chart inside a sheet, use this macro:

Sub SetChartTitle()
    Dim s As Shape
    Dim i as integer
    i = 1

    For Each s In Sheets("Sheet1").Shapes
        If s.HasChart Then
            s.Name = "mychart" & i ' set the chart name
            i = i + 1
        End If
    Next s
End Sub

You can even use this loop to export all your charts with s.Chart.Export

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top