Excel® 2007 VBA Programmer's Reference
by John Green, Stephen Bullen, Rob Bovey, Michael Alexander
Chapter 8. Charts
In this chapter, you see how you can use the macro recorder to discover what objects, methods, and properties are required to manipulate charts. You will then improve and extend that code to make it more flexible and efficient. This chapter is designed to show you how to gain access to Chart objects in VBA code so that you can start to program the vast number of objects that Excel charts contain. You can find more information on these objects in Appendix A. Specifically, this chapter examines:
Creating
Chartobjects on separate sheetsCreating
Chartobjects embedded in a worksheetEditing data series in charts
Defining series with arrays
Defining chart labels
You can create two types of charts in Excel: charts that occupy their own chart sheets and charts that are embedded in a worksheet. They can be manipulated in code in much the same way. The only difference is that, whereas the chart sheet is a Chart object in its own right, the chart embedded in a worksheet is contained by a ChartObject object. Each ChartObject on a worksheet is a member of the worksheet's ChartObjects collection. Chart sheets are members of the workbook's Charts collection.
Each
ChartObjectis a member of theShapescollection, as well as a member of theChartObjectscollection. TheShapescollection provides you with an alternative way to refer to embedded charts. The macro recorder generates code that uses theShapescollection rather than theChartObjectscollection.
Chart Sheets
Select the data ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access