PC Review


Reply
Thread Tools Rate Thread

ChartObject.Copy *very* slow

 
 
Chrisso
Guest
Posts: n/a
 
      28th Mar 2008
Hi All

I have some code where I use a templated chart to make a copy:

Debug.Print " MC 0: " & Now()
Dim chtObjTemplate As ChartObject, wsCharts As Worksheet
Set wsCharts = ThisWorkbook.Sheets("Charts")
Set chtObjTemplate = wsCharts.ChartObjects("Chart 1")
chtObjTemplate.Copy
Debug.Print " MC 1: " & Now()

I am surprised to find that this takes roughly 5 seconds as the debug
statements show:
MC 0: 27/03/08 08:51:45
MC 1: 27/03/08 08:51:50

My code turns off the screen, disables events and sets calculation to
manual:
Application.ScreenUpdating = False
Application.Calculation = xlManual
Application.EnableEvents = False

So does anyone have any idea why this is taking so long and how to
get
around it? This amount of time per chart copy will mean my solution
will not scale.

Is there a better way to ensure that a chart generated automatically
matches the formatting of another chart?

Thanks in advance,
Chrisso
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      28th Mar 2008
What version of Excel?

I prefer working with chart objects in this context as well, but what if you
use

chtObjTemplate.Chart.Copy

You could copy a properly formatted chart, select your unformatted chart,
and use paste special - formats to apply the formats to the second chart.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Chrisso" <(E-Mail Removed)> wrote in message
news:98e22204-8d51-4140-abcc-(E-Mail Removed)...
> Hi All
>
> I have some code where I use a templated chart to make a copy:
>
> Debug.Print " MC 0: " & Now()
> Dim chtObjTemplate As ChartObject, wsCharts As Worksheet
> Set wsCharts = ThisWorkbook.Sheets("Charts")
> Set chtObjTemplate = wsCharts.ChartObjects("Chart 1")
> chtObjTemplate.Copy
> Debug.Print " MC 1: " & Now()
>
> I am surprised to find that this takes roughly 5 seconds as the debug
> statements show:
> MC 0: 27/03/08 08:51:45
> MC 1: 27/03/08 08:51:50
>
> My code turns off the screen, disables events and sets calculation to
> manual:
> Application.ScreenUpdating = False
> Application.Calculation = xlManual
> Application.EnableEvents = False
>
> So does anyone have any idea why this is taking so long and how to
> get
> around it? This amount of time per chart copy will mean my solution
> will not scale.
>
> Is there a better way to ensure that a chart generated automatically
> matches the formatting of another chart?
>
> Thanks in advance,
> Chrisso



 
Reply With Quote
 
Chrisso
Guest
Posts: n/a
 
      28th Mar 2008
Hi Jon

I am running Excel 2002 10.2614

I tried:
chtObjTemplate.Chart.Copy
but this gave an error ("Run time Error 1004 : Method 'Copy' of object
'_Chart' failed")

So I tried:
chtObjTemplate.Chart.ChartArea.Copy
and this was *much* faster and did the same job.

Thanks for you help - much appreciated.

Chrisso


On 28 Mar, 13:42, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
wrote:
> What version of Excel?
>
> I prefer working with chart objects in this context as well, but what if you
> use
>
> * * chtObjTemplate.Chart.Copy
>
> You could copy a properly formatted chart, select your unformatted chart,
> and use paste special - formats to apply the formats to the second chart.
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. -http://PeltierTech.com
> _______
>
> "Chrisso" <chris75sut...@gmail.com> wrote in message
>
> news:98e22204-8d51-4140-abcc-(E-Mail Removed)...
>
>
>
> > Hi All

>
> > I have some code where I use a templated chart to make a copy:

>
> > * *Debug.Print " * *MC 0: " & Now()
> > * *Dim chtObjTemplate As ChartObject, wsCharts As Worksheet
> > * *Set wsCharts = ThisWorkbook.Sheets("Charts")
> > * *Set chtObjTemplate = wsCharts.ChartObjects("Chart 1")
> > * *chtObjTemplate.Copy
> > * *Debug.Print " * *MC 1: " & Now()

>
> > I am surprised to find that this takes roughly 5 seconds as the debug
> > statements show:
> > * *MC 0: 27/03/08 08:51:45
> > * *MC 1: 27/03/08 08:51:50

>
> > My code turns off the screen, disables events and sets calculation to
> > manual:
> > * *Application.ScreenUpdating = False
> > * *Application.Calculation = xlManual
> > * *Application.EnableEvents = False

>
> > So does anyone have any idea why this is taking so long and how to
> > get
> > around it? This amount of time per chart copy will mean my solution
> > will not scale.

>
> > Is there a better way to ensure that a chart generated automatically
> > matches the formatting of another chart?

>
> > Thanks in advance,
> > Chrisso- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Jon Peltier
Guest
Posts: n/a
 
      28th Mar 2008
Oh yeah, ChartArea. If I'd actually tried it, I would have posted the
correct code. Glad you figured it out.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"Chrisso" <(E-Mail Removed)> wrote in message
news:83c755f7-02f1-4ff0-9702-(E-Mail Removed)...
Hi Jon

I am running Excel 2002 10.2614

I tried:
chtObjTemplate.Chart.Copy
but this gave an error ("Run time Error 1004 : Method 'Copy' of object
'_Chart' failed")

So I tried:
chtObjTemplate.Chart.ChartArea.Copy
and this was *much* faster and did the same job.

Thanks for you help - much appreciated.

Chrisso


On 28 Mar, 13:42, "Jon Peltier" <jonxlmv...@SPAMpeltiertech.com>
wrote:
> What version of Excel?
>
> I prefer working with chart objects in this context as well, but what if
> you
> use
>
> chtObjTemplate.Chart.Copy
>
> You could copy a properly formatted chart, select your unformatted chart,
> and use paste special - formats to apply the formats to the second chart.
>
> - Jon
> -------
> Jon Peltier, Microsoft Excel MVP
> Tutorials and Custom Solutions
> Peltier Technical Services, Inc. -http://PeltierTech.com
> _______
>
> "Chrisso" <chris75sut...@gmail.com> wrote in message
>
> news:98e22204-8d51-4140-abcc-(E-Mail Removed)...
>
>
>
> > Hi All

>
> > I have some code where I use a templated chart to make a copy:

>
> > Debug.Print " MC 0: " & Now()
> > Dim chtObjTemplate As ChartObject, wsCharts As Worksheet
> > Set wsCharts = ThisWorkbook.Sheets("Charts")
> > Set chtObjTemplate = wsCharts.ChartObjects("Chart 1")
> > chtObjTemplate.Copy
> > Debug.Print " MC 1: " & Now()

>
> > I am surprised to find that this takes roughly 5 seconds as the debug
> > statements show:
> > MC 0: 27/03/08 08:51:45
> > MC 1: 27/03/08 08:51:50

>
> > My code turns off the screen, disables events and sets calculation to
> > manual:
> > Application.ScreenUpdating = False
> > Application.Calculation = xlManual
> > Application.EnableEvents = False

>
> > So does anyone have any idea why this is taking so long and how to
> > get
> > around it? This amount of time per chart copy will mean my solution
> > will not scale.

>
> > Is there a better way to ensure that a chart generated automatically
> > matches the formatting of another chart?

>
> > Thanks in advance,
> > Chrisso- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
ChartObject.Copy very slow Chrisso Microsoft Excel Programming 0 27th Mar 2008 09:00 AM
ChartObject.Copy very slow Chrisso Microsoft Excel Programming 0 27th Mar 2008 09:00 AM
HELP! Very slow file copy,snif shows TCP retransmit, slow ack,smb command rejected etc.etc. .:mmac:. Microsoft Windows 2000 Networking 0 4th Jun 2005 02:18 AM
chartobject alldreams Microsoft Excel Programming 3 24th Mar 2004 09:14 PM
chartobject alldreams Microsoft Excel Programming 6 24th Mar 2004 03:48 PM


Features
 

Advertising
 

Newsgroups
 


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