VBA - Save Charts with Chart Title as Name

smitpau

Board Regular
Joined
Apr 2, 2020
Messages
167
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'd like to be able to save all Charts in a sheet with their Chart Title as their name, for some reason this is proving more difficult than expected.

I believe it's the Title = part of the code that needs to be changed.

Any help would be appreciated.

Code:

Sub ExportSheetCharts()

'Create a variable to hold the path and name of image
Dim cht As ChartObject
Dim strUserName As String
Dim Title As String
strUserName = Application.UserName
Title = ChartObject.ChartTitle

ActiveSheet.ChartObjects.Select

'Export the chart
For Each cht In ActiveSheet.ChartObjects
cht.Chart.Export "C:\Users\" & strUserName & "\Pictures\" & Title & x & ".png"
x = x + 1
Next cht

End Sub

Thanks,
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
ChartObjects don't have a ChartTitle property, and you haven't specified which chartobject you were referring to in your code. All you should need is:

Code:
Sub ExportSheetCharts()

'Create a variable to hold the path and name of image
Dim cht As ChartObject
Dim strUserName As String

strUserName = Application.UserName


'Export the chart
           For Each cht In ActiveSheet.ChartObjects
           cht.Chart.Export "C:\Users\" & strUserName & "\Pictures\" & cht.Chart.ChartTitle & x & ".png"
           x = x + 1
       Next cht

End Sub
 
Upvote 0
Thanks for responding RoryA when I try this it says "Object doesn't support this property or method" unfortunately.
 
Upvote 0
Try using cht.Chart.ChartTitle.Text rather than cht.Chart.ChartTitle (assuming all your charts actually have a title)
 
Upvote 0

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top