Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default ChartObjects

I am writing a VB routine to copy a chart from 20 workbooks to a new single
worksheet in a new workbook. I will also update the charts in the new
workbook perodically. The following will be called 20 times with a different
Oneof20 and ChartLoc.

Sub CopyGraph (Oneof20 As String, ChartLoc As String)
'
' Open workbook
Workbooks.Open Filename:= Oneof20
Windows(EachFile).Activate
Sheets("XYZ").Select

'
'Copy new chart
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
'
' paste new chart
Windows("ALL.xls").Activate
Sheets("20Charts").Select
Range(ChartLoc).Select
ActiveSheet.Paste
'
' change chart title
ActiveSheet.ChartObjects(ChartName).Activate
..
..
..

How can I determine what ChartName is? If I do the "copy the 20 charts" a
2nd time (say a month later), I will have to delete the original 20 charts
first. How do I get the names of those 20 charts so I can reference them to
delete?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default ChartObjects

Scott,

Your procedure is attempting to activate a chart that will already be
active. When you paste the chart it becomes the active item. So if you want
to get the name of the chart you just need to use ActiveChart.Name. You
could use a blank sheet to list the chart names

Sheet1.Range("A65536").End(xlUp).Offset(1, 0) = ActiveChart.Name

and then reference this list when you want to delete the charts

Sheets("20charts").Activate
For Each chartname In ActiveSheet.ChartObjects
Set rng = Sheet1.Range("A2", Range("A65536").End(xlUp))
MsgBox (rng.Address & " " & chartname.Name)
Set found = rng.Find(chartname.Name)
If Not found Is Nothing Then chartname.Delete
Next chartname

Where Sheet1 is the sheet you write the chartnames to.

Hope this helps you out.

Mike



"Scott" wrote:

I am writing a VB routine to copy a chart from 20 workbooks to a new single
worksheet in a new workbook. I will also update the charts in the new
workbook perodically. The following will be called 20 times with a different
Oneof20 and ChartLoc.

Sub CopyGraph (Oneof20 As String, ChartLoc As String)
'
' Open workbook
Workbooks.Open Filename:= Oneof20
Windows(EachFile).Activate
Sheets("XYZ").Select

'
'Copy new chart
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select
ActiveChart.ChartArea.Copy
ActiveWindow.Visible = False
'
' paste new chart
Windows("ALL.xls").Activate
Sheets("20Charts").Select
Range(ChartLoc).Select
ActiveSheet.Paste
'
' change chart title
ActiveSheet.ChartObjects(ChartName).Activate
.
.
.

How can I determine what ChartName is? If I do the "copy the 20 charts" a
2nd time (say a month later), I will have to delete the original 20 charts
first. How do I get the names of those 20 charts so I can reference them to
delete?

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
Problems with ChartObjects pwermuth[_5_] Excel Programming 5 July 12th 05 11:19 PM
Looping Through Charts / ChartObjects William Benson[_2_] Excel Programming 2 June 29th 05 01:47 AM
delete chartobjects! Magnus Excel Programming 1 May 10th 05 01:01 PM
Not allow selection of chartobjects ? Gunnar Johansson Charts and Charting in Excel 0 May 8th 05 01:40 PM
ChartObjects Nick Excel Programming 2 August 19th 04 12:04 PM


All times are GMT +1. The time now is 06:19 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"