Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Add a Chart as the last sheet

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Add a Chart as the last sheet

Thanks for your response.

The period did not affect the behavior.

And I tried counting Sheets instead of worksheets and it still does the same.

With excelBook
..Sheets.Add After:=.Sheets(.Sheets.Count), Type:=xlChart
End With
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Add a Chart as the last sheet


I tried counting sheets as well as the period.

But that didnt have any affect on the issue.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Add a Chart as the last sheet

It works for everyone else. Only thing I have seen that will affect it is
hidden sheets. What method are you using to move it to the last sheet after
insertion. Isn't it the same approach?

guess you could loop through all the sheets and retain a reference to the
last sheet.

--
Regards,
Tom Ogilvy


"BilalD" wrote in message
...

I tried counting sheets as well as the period.

But that didnt have any affect on the issue.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Add a Chart as the last sheet

I do the following to move the sheet to the end. Not the best way, but it
works.

Set excelchart(0) = excelBook.Sheets("Chart1")
excelchart(0).Move after:=excelBook.Sheets(excelBook.Sheets.Count)

Sheets.Count is returning the correct number of sheets. I am not doing
anything with hidden sheets, unless Excel has some hidden sheet alwasy
include. But if that were the case, then the move method would not have
worked.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Add a Chart as the last sheet

Just like I said, you are using the exact same code as what I suggested to
determine what the last sheet is. In one case you say it doesn't work and
in this case you say it does.

Perhaps you didn't add the period and use Sheets after all. Just a guess.

--
Regards,
Tom Ogilvy

"BilalD" wrote in message
...
I do the following to move the sheet to the end. Not the best way, but it
works.

Set excelchart(0) = excelBook.Sheets("Chart1")
excelchart(0).Move after:=excelBook.Sheets(excelBook.Sheets.Count)

Sheets.Count is returning the correct number of sheets. I am not doing
anything with hidden sheets, unless Excel has some hidden sheet alwasy
include. But if that were the case, then the move method would not have
worked.





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Add a Chart as the last sheet

Hi

Based on my research, so far we do need to use the Move to add the chart
after the last sheet.

Sub Test()
Application.ScreenUpdating = False ' Prevents screen refreshing.
Charts.Add
ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)
Application.ScreenUpdating = True ' Enables screen refreshing.
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Add a Chart as the last sheet

Thanks for your help everyone. It would be nice to have this documented. It's
easy enough to fix (on the client side), but irritating none the less.

""Peter Huang" [MSFT]" wrote:

Hi

Based on my research, so far we do need to use the Move to add the chart
after the last sheet.

Sub Test()
Application.ScreenUpdating = False ' Prevents screen refreshing.
Charts.Add
ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)
Application.ScreenUpdating = True ' Enables screen refreshing.
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Add a Chart as the last sheet

Hi

Thank you for your feedback.
And if you still have any concern, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Add a Chart as the last sheet

This is a bug that has existed since at least the early/mid '90s. You
have to do what you are already doing: add the sheet and then move it
to the correct location.

When needed, I add a module called ExcelFUs to an add-in. A
'AddAtEnd' function is a standard component of such a module.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
am says...
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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save chart (that's on a chart sheet) to html file? JoeFrench Charts and Charting in Excel 0 January 24th 08 12:11 PM
Check Activesheet for chart sheet or work sheet NSK Charts and Charting in Excel 1 July 17th 07 09:00 PM
???Replicate a sheet but chart still link to original sheet Jaylin Charts and Charting in Excel 1 October 9th 06 03:14 PM
Moving Pivot Chart Fields on a chart sheet sherobot Charts and Charting in Excel 1 April 28th 06 10:08 PM
Dynamic column chart - copying from Sheet to Sheet. Marko Pinteric Charts and Charting in Excel 1 April 10th 06 12:57 PM


All times are GMT +1. The time now is 07:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"