User Defined Chart Declaration VBA

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
After much searching i managed to find a list of ways to declare in VBA the type of chart you like, eg. xlCylinderBarClustered, xlXYScatterLines, xlLineStacked, xlPie etc, how though do i declare my user defined charts? or is there also a way that you can play with the formatting of the chart colour and appearance etc. For example one of my fave charts uses coloured outlines for the bars and white centres, i always like a white background etc etc

Any help would be gratefully received

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Jon Peltier

MrExcel MVP
Joined
May 14, 2003
Messages
4,983
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
To save your own custom chart type, right click on the chart, select Save As Template, and use the dialog to save a new chart template.

In code it looks like:
VBA Code:
    ActiveChart.SaveChartTemplate "C:\Users\Jon Peltier\AppData\Roaming\Microsoft\Templates\Charts\MrExcelChart.crtx"

The path in the command above is the official place to store templates where Excel will find them. Change my name to your Windows user name.

To apply your custom template to a chart, right click the chart, choose Change Chart Type, click on the Templates folder, and select the template to use.

In code:
VBA Code:
    ActiveChart.ApplyChartTemplate "C:\Users\Jon Peltier\AppData\Roaming\Microsoft\Templates\Charts\MrExcelChart.crtx"

To create a new chart using your template, select the data, go to the Insert tab, click the little icon at the bottom right corner of the Charts group ("See All Charts"), click on All Charts, click on the Templates folder, and select your template.

In code, you have to create a chart using any chart type, then apply the code as above to change to your template:
VBA Code:
    ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
    ActiveChart.ApplyChartTemplate "C:\Users\Jon Peltier\AppData\Roaming\Microsoft\Templates\Charts\MrExcelChart.crtx"
    ActiveChart.SetSourceData Source:=Range("Sheet2!$B$2:$C$9")

Change Sheet2!B2:C9 to your data range.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,857
Messages
5,766,792
Members
425,379
Latest member
thedoctor00

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
Top