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
Chart
objects on separate sheetsCreating
Chart
objects 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
ChartObject
is a member of theShapes
collection, as well as a member of theChartObjects
collection. TheShapes
collection provides you with an alternative way to refer to embedded charts. The macro recorder generates code that uses theShapes
collection rather than theChartObjects
collection.
Chart Sheets
Select the data ...
Get Excel® 2007 VBA Programmer's Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.