View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
WhytheQ WhytheQ is offline
external usenet poster
 
Posts: 246
Default Copying Charts: CODE NOT ROBUST

Can anyone help.
The code I'm using is:

Dim sheet
Dim Chart

'loop through all the embedde charts in a particular sheet
For Each Chart In sheet.ChartObjects

'activate the chart and move it to it's own sheet
Chart.Activate
ActiveChart.Location Whe=xlLocationAsNewSheet, Name:=mySheetName

'now copy the chart worksheet to a different workbook
ActiveSheet.Copy
Workbooks(myFileName).Sheets(Workbooks(myFileName) .Sheets.Count)

'in thisworkbook move the chart back to being an embedded chart object
ThisWorkbook.Activate
ActiveChart.Location Whe=xlLocationAsObject, Name:=sheet.Name

Next Chart

I've used the above procedure because I just want the charts to be
embedded objects in the main spreadsheet rather than having a load of
Chartsheets aswell as worksheets.
Problem with the above is that it seems to throw an unknown error, and
then when I go into the code window and go for Debug and then step
through the macro all seems ok: but when I come to exit the spreadsheet
and save changes a nasty Dr Watson occurs - and all Excel is lost.
So I believe the above is doing something particularly nasty to Excel.

Any help greatly appreciated
Jason.