[RESOLVED] "You must select a shape"
Hey all -- I've been having some trouble with some VBCode, below.
Code:
Dim shtData As Worksheet
Application.ScreenUpdating = False
' oExcel.Sheets(Layer).Activate **The variable Layer is the
current Excel sheet being generated**
Set shtData = Layer
shtData.Activate
Set shtData = ActiveSheet
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=shtData.Range("M23")
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = _
Worksheets("Layer " & i).Range("A13:A58")
ActiveChart.SeriesCollection(1).Values = _
Worksheets("Layer " & i).Range("A13:A58")
ActiveChart.SeriesCollection(2).XValues = _
Worksheets("Layer " & i).Range("B13:B58")
ActiveChart.SeriesCollection(2).Values = _
Worksheets("Layer " & i).Range("B13:B58")
ActiveChart.Location Where:=xlLocationAsObject, Name:=Layer
What this code does is iteratively go through an excel list of variable size, and adds an embedded chart to each of them. This is during a setup phase where the larger code generates a whole excel doc.
It has been functioning in three different ways, depending on how I play with the code (comment out lines, etc). 1. It goes through and generates the Excel document properly, but without charts. 2. It goes through and generates the Excel document properly, but the charts are in their own sheets (not embedded). 3. It goes through and generates the Excel document properly, with charts, but during setup, I get the error "You must select a shape" for each sheet in the Excel document. The number of sheets can be over 125, so it's an issue.
I wonder if any of you have any insight? If you need more detail, I'm happy to provide.
Re: "You must select a shape"
Might be better to assign the chart into an object..?
instead of activechart...
eg
Code:
dim cht as Chart
' other bits of code
set cht = Charts.Add
'---- clean up after use
set cht = nothing
Also once it is in a sheet, it is no longer a chart, it is a shape and much harder to manipulate in code...
Re: "You must select a shape"
Quote:
Originally Posted by
Ecniv
Might be better to assign the chart into an object..?
instead of activechart...
eg
Code:
dim cht as Chart
' other bits of code
set cht = Charts.Add
'---- clean up after use
set cht = nothing
Also once it is in a sheet, it is no longer a chart, it is a shape and much harder to manipulate in code...
Thank you ecniv, that worked perfectly!