The Default Chart Type

You will notice that code does not specify the chart type being created, yet a column chart was produced. On my machine, the default chart type for Excel is a column chart. This is an important feature of Excel VBA. Defaults that are saved as Excel settings need not be explicitly specified in VBA code.

This can work for you or against you. On the positive side, if you need to create many charts of one particular type, you can change the default chart type on your machine and produce code to create that default chart. However, be aware that this also can work against you. Probably 98% of people don't know how to change their default chart type and so Charts.Add works as you expect in many cases. However, as you distribute your code to all the department managers, you will undoubtedly find the regional manager in Sioux City read a book and changed his default chart type to a pie chart. He will end up with dramatically different charts if you rely on Charts.Add without explicitly coding which type of chart you want.

When you want to override any default chart parameter, you need to add several lines of code. For example, the plot area of the default chart is an ugly gray. If you want to replace this with white, you need to add the following line of code:

ActiveChart.PlotArea.Interior.Colorlndex = xlNone

To change your default chart type, right-click any chart and choose Chart Type from the popup menu. Select a chart type,and click Set As Default Chart in the lower-left corner of the dialog.

Was this article helpful?

0 0

Post a comment