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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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.
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,058
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