Export charts to image file using VBA?

richanor

Active Member
Joined
Apr 8, 2006
Messages
291
Dear all

Is it possible to export a batch of charts to individual image files using VBA?

I have a workbook containing a sheet called 'charts'. On this sheet there are 60 mini charts set up like a sort of dashboard. I am wondering whether it is possible to export each of these charts to a seperate image file using VBA?

The location of the image files would just be a local folder, and the file names could either be automotically numbered (1.jpg, 2.jpg etc) or could be based upon the contents of a series of cells: the way the sheet is set up is that the range D2:G16 each contains the title of a chart. The respective chart is positioned over the cell. I am guessing that since there is no logical link between the chart and the cell (is there?) other than the position on the page, that it would not be possible to use the cell contents as a file name?

If somebody could let me know firstly if it is possible to export a chart to an image file, that would be great. If you are able to offer any help with a script - even better!

many thanks

Rich
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
You can certainly do that. If the chart is positioned so that its top left corner is within the cell that contains its title, then that is pretty easy to add in. Something like:
Code:
Dim objCht as ChartObject
For each objCht in Activesheet.Chartobjects
objCht.Chart.Export "C:\folder\" & objcht.topleftcell.Value & ".jpg", "JPG"
next objCht
 
Upvote 0
Hi all

Rory helped me out with this code yesterday, which works great, but I just realised that because the charts are set up in a sort of dashboard style - they are pretty tiny. I had not realised that they will export to an image file at the same size!

Could somebody help me out ammending this code to resize the charts? (Ideally to something like 480 X 320)

many thanks again

Rich
 
Upvote 0

Forum statistics

Threads
1,214,666
Messages
6,120,806
Members
448,990
Latest member
rohitsomani

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