View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Add a Chart as the last sheet

Your missing a period in this line

With excelBook
..Sheets.Add After:=.Worksheets(Worksheets.Count), Type:=xlChart
End With

the worksheet.count should start with a period.

Perhaps that is the problem.

another think is your counting worksheets and perhaps that is what you want,
but since you have charts as well, you might want to use Sheets instead of
worksheets

With excelBook
..Sheets.Add After:=.Sheets(.Sheets.Count), Type:=xlChart
End With

--
Regards,
Tom Ogilvy



--
Regards,
Tom Ogilvy



"BilalD" wrote in message
...
Hello all

I am trying to add a chart as the very last sheet in a workbook. I have

the
following VB 6.0 code. Using Excel 2003.

Option Explicit
Dim excelApp As New Excel.Application
Dim excelBook As Excel.Workbook

Dim excelSheet(0 To 3) As Excel.Worksheet
Dim excelchart(0 To 3) As Excel.Chart

Private Sub Command1_Click()

excelApp.Visible = True
Set excelBook = excelApp.Workbooks.Add
Set excelSheet(0) = excelBook.Worksheets.Add

With excelBook
.Sheets.Add After:=.Worksheets(Worksheets.Count), Type:=xlChart
End With

End Sub

What I notice is that even though I specify to add the chart after the

very
last sheet, it already adds it right before the last. I didnt see anything

in
the documentation that would lead me to believe that this is expect

behavior.
I know I can move the chart to be the last sheet and thats how Im working
around this.

Did I just miss something? Can someone shed some light on this behavior?

It
might have to do with adding sheets of different types, because I dont see
this happen if I add a WorkSheet instead of a chart.

I know im not the only one seeing this.

Thanks.