VBA Code to Export Chart to png

lbth

New Member
Joined
Feb 18, 2011
Messages
3
Morning all, just joined as can not find the answer to a question I have searched for hours to try and solve. I have done this in the past but can not find the original file, or page showing how to do it.

All I want is a simple way to export named charts from within vba, the best guess I could come up with was this:

Sub Export()

Charts(ChartName).Activate
With ActiveChart
ActiveChart.Export "C:\MAPBOOK_OUTPUTS\ChartName.png"

End Sub

Thanks in advance for any help!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Welcome to the board,

I believe this will help you activate the chart then you use your line of code to create the object

Worksheets(1).ChartObjects(2).Activate
ActiveChart.Export "C:\MAPBOOK_OUTPUTS\ChartName.png"
 
Upvote 0
Hi Trevor, thanks for the welcome and the fast reply. Much appreciated!

Sorry but please excuse my terrible vba skills, I inserted your code like so:

Sub Export()

Worksheets(TABLES).ChartObjects(SusAge).Activate
ActiveChart.Export "C:\MAPBOOK_OUTPUTS\ChartName.png"

End Sub

This is where TABLES is the name of the worksheet and SusAge is the name I have given to the chart.

Any ideas? I am assuming I am missing something simple??

Thanks again.
 
Upvote 0
You aren't far off, worksheet names go inside speech marks, if you named the object then record a macro to find the object and in the code it will let you know if you need speech marks there to

Sub Export()

Worksheets("TABLES").ChartObjects(SusAge).Activate
ActiveChart.Export "C:\MAPBOOK_OUTPUTS\SusAge.png"

End Sub
 
Upvote 0
Trevor, I could kiss you right now!!!!

Thanks very much, as assumed was something simple. Just needed speech marks for both the Worksheet and chartname.

Thanks very much mate. Have a good weekend!
 
Upvote 0
Pleased to read you have a solution. ;)

I hope to have a good weekend and in return hope you do to.
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,047
Members
448,940
Latest member
mdusw

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