Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Copying Charts: CODE NOT ROBUST

Here is a possible workaround:

dim sht as Worksheet
Dim cobj as ChartObject
Dim cobj1 as ChartObject
set sht = Activesheet
For Each cObj In sheet.ChartObjects
sht.copy ' makes a new workbook with all chart Objects
' now delete all but the one you want
for each cobj1 in activesheet.ChartObjects
if cobj1.name < cObj.Name then
cobj1.Delete
end if
next
ActiveWorkbook.SaveAs "C:\Myfolder\" & cobj.Name & ".xls"
ActiveWorkbook.Close Savechanges:=False
Next


--
Regards,
Tom Ogilvy



"WhytheQ" wrote:

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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Copying Charts: CODE NOT ROBUST

cheers Tom
Jason


Tom Ogilvy wrote:
Here is a possible workaround:

dim sht as Worksheet
Dim cobj as ChartObject
Dim cobj1 as ChartObject
set sht = Activesheet
For Each cObj In sheet.ChartObjects
sht.copy ' makes a new workbook with all chart Objects
' now delete all but the one you want
for each cobj1 in activesheet.ChartObjects
if cobj1.name < cObj.Name then
cobj1.Delete
end if
next
ActiveWorkbook.SaveAs "C:\Myfolder\" & cobj.Name & ".xls"
ActiveWorkbook.Close Savechanges:=False
Next


--
Regards,
Tom Ogilvy



"WhytheQ" wrote:

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.



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
Copying Charts Keith Charts and Charting in Excel 3 August 4th 08 04:07 PM
copying vba code to a standard code module 1vagrowr Excel Discussion (Misc queries) 2 November 23rd 05 04:00 PM
Are there functions that perform robust statistics in Excel? froot_broot Excel Worksheet Functions 0 August 30th 05 10:18 PM
Can someone help me make this code more robust? Henry Stock Excel Programming 1 February 23rd 05 05:26 PM
Sheet Code Module: copying code to [email protected][_2_] Excel Programming 2 December 14th 04 01:57 AM


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

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

About Us

"It's about Microsoft Excel"