Capture chart elements in VB

O

obts1434

Is there anyway, if I have an existing chart that is formatted already, to
capture the all elements of that chart in VB (by recording a macro perhaps)?

Have a spreadsheet that contains hundreds of charts, all of which are the
same format, but due to non-adjacent data sources and multiple chart types
within one chart, it's very tempermental - need to standardize.

Also, is there a list contained within a spreadsheet of all components of
that spreadsheet? Primarily trying to capture the chart names to utilize in
VB coding without having to start recording a macro and then selecting each
and every chart.
 
J

Jon Peltier

Is there anyway, if I have an existing chart that is formatted already, to
capture the all elements of that chart in VB (by recording a macro perhaps)?

You want to capture the formats? You can copy a chart, then paste
special as formats only. This overwrites your chart title and axis
titles, so in a VBA procedure, you should store these text items in
string variables, then copy-paste the format, then reapply the titles.

This might be a use for user-defined chart types, as well:

http://peltiertech.com/Excel/ChartsHowTo/CreateCustomTypes.html

Again, note that the titles are hosed.
Have a spreadsheet that contains hundreds of charts, all of which are the
same format, but due to non-adjacent data sources and multiple chart types
within one chart, it's very tempermental - need to standardize.

Also, is there a list contained within a spreadsheet of all components of
that spreadsheet? Primarily trying to capture the chart names to utilize in
VB coding without having to start recording a macro and then selecting each
and every chart.

To get a list of chart object names:

For Each chobChartObject in ActiveSheet.ChartObjects
Debug.Print chobChartObject.Name
Next

To run a macro on each embedded chart

For Each chobChartObject in ActiveSheet.ChartObjects
With chobChartObject.Chart
' your code goes here
End With
Next

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top