Microsoft Office Tutorials and References
In Depth Information
21.2.3 An Example of Chart Creation
Note that, although the documentation does not discuss the matter, experimentation shows that the
Name property of the Chart object appears to be read-only. Indeed, the code:
co.Chart.Name = "AChart"
results in the error message: "Method Name of object _Chart failed."
Note also that we can run the CreateAChart procedure multiple times without error and this
will produce multiple ChartObject objects with the same name! Thus, the name property seems to
be of little use for both ChartObject objects and embedded Chart objects. In fact, after running the
CreateAChart procedure twice and getting two charts named ExampleChart, the code:
Debug.Print ActiveSheet.ChartObjects(1).Name
Debug.Print ActiveSheet.ChartObjects(2).Name
ActiveSheet.ChartObjects("ChartExample").Left = 600
actually produces the output:
ChartExample
ChartExample
and moves one of the charts to the new position specified by the Left property!
21.2.3 An Example of Chart Creation
As we have said, creating a useful chart from scratch requires using the properties and methods of
the Chart object. As we will see, this object is quite complex, with a great many properties,
methods, and children. Before plunging into a discussion of these items, we want to give an
example of chart creation. This will put our future discussion into some perspective. In fact, we
will have several occasions to make reference to this code in the sequel.
Figure 21-5. The results of CreateChart
So, the CreateChart procedure shown in Example 21-2 produces the chart in Figure 21-5 . It
may not be pretty, but it does illustrate much of the chart making process.
Example 21-2. The CreateChart Procedure
Sub CreateChart()
' Create an embedded chart
 
 
 
 
Search JabSto ::




Custom Search