Microsoft Office Tutorials and References
In Depth Information
Creating an Embedded Chart
h Top: The top position of the chart, in points. If omitted, Excel centers the chart vertically.
h Width: The width of the chart, in points. If omitted, Excel uses 354.
h Height: The height of the chart, in points. If omitted, Excel uses 210.
In many cases, you may find it efficient to create an object variable when the chart is created.
The following procedure creates a line chart that you can reference in code by using the
MyChart object variable:
Sub CreateChart()
Dim MyChart As Chart
Set MyChart = ActiveSheet.Shapes.AddChart(xlLineMarkers).Chart
End Sub
A chart without data isn’t very useful, so you’ll want to use the SetSourceData method to add
data to a newly created chart. The procedure that follows demonstrates the SetSourceData
method. This procedure creates the chart shown in Figure 18-1.
Sub CreateChart()
Dim MyChart As Chart
Dim DataRange As Range
Set DataRange = ActiveSheet.Range(“A1:C7”)
Set MyChart = ActiveSheet.Shapes.AddChart.Chart
MyChart.SetSourceData Source:=DataRange
End Sub
Figure 18-1: A few lines of VBA code created this chart.
 
Search JabSto ::




Custom Search