Page 243 - Excel Progamming Weekend Crash Course
P. 243

n540629 ch17.qxd  9/2/03  9:35 AM  Page 218




                218                                                         Saturday Evening


               Listing 17-3  Creating an embedded chart with titles

                  Public Sub CreateEmbeddedChartWithTitles()

                  Dim co As ChartObject
                  Dim ch As Chart

                  Set co = Worksheets(“Sheet1”).ChartObjects.Add(50, 100, 250, 165)
                  Set ch = co.Chart
                  ch.SetSourceData Source:=Worksheets(“Sheet1”).Range(“B3:F6”),
                  PlotBy:=xlRows
                  ‘ Add a chart title.
                  ch.HasTitle = True
                  ch.ChartTitle.Text = “Ice Cream Sales”
                  ‘ Add a category axis title.
                  ch.Axes(xlCategory).HasTitle = True
                  ch.Axes(xlCategory).AxisTitle.Text = “Period”
                  ‘ Add a value axis title.
                  ch.Axes(xlValue).HasTitle = True
                  ch.Axes(xlValue).AxisTitle.Text = “Sales in Gallons”

                  End Sub

































                    Figure 17-6 The chart created by the program in Listing 17-3
   238   239   240   241   242   243   244   245   246   247   248