Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default I get two copies of pictures in the loop instead of one - why?

Hi,

I have a sheet where I in Worksheet_Activate copy all chartobjects and paste
them as pictures and then hide the chartobjects. This make the users not
able to ruin the references in the charts.

Problem: I get two copies of pictures...why????

She sheet1 had to have a couple of charts. Code:

Sub CopyChart()
Dim chtobj As ChartObject
Dim W As Double
Dim H As Double
Dim T As Double
Dim L As Double

ActiveSheet.Unprotect
ActiveSheet.Pictures.Delete

For Each chtobj In Sheet1.ChartObjects
W = chtobj.Width
H = chtobj.Height
L = chtobj.Left
T = chtobj.Top
chtobj.CopyPicture Appearance:=xlScreen, Format:=xlPicture

ActiveSheet.Pictures.Paste.Select
With Selection
.Width = W
.Height = H
.Left = L
.Top = T
End With
Next chtobj

ActiveSheet.ChartObjects.Visible = False
Exit Sub

/Regards


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default I get two copies of pictures in the loop instead of one - why?

What triggers your macro? Maybe you are running it twice.

--
Regards,
Tom Ogilvy

"Maria High" wrote in message
...
Hi,

I have a sheet where I in Worksheet_Activate copy all chartobjects and

paste
them as pictures and then hide the chartobjects. This make the users not
able to ruin the references in the charts.

Problem: I get two copies of pictures...why????

She sheet1 had to have a couple of charts. Code:

Sub CopyChart()
Dim chtobj As ChartObject
Dim W As Double
Dim H As Double
Dim T As Double
Dim L As Double

ActiveSheet.Unprotect
ActiveSheet.Pictures.Delete

For Each chtobj In Sheet1.ChartObjects
W = chtobj.Width
H = chtobj.Height
L = chtobj.Left
T = chtobj.Top
chtobj.CopyPicture Appearance:=xlScreen, Format:=xlPicture

ActiveSheet.Pictures.Paste.Select
With Selection
.Width = W
.Height = H
.Left = L
.Top = T
End With
Next chtobj

ActiveSheet.ChartObjects.Visible = False
Exit Sub

/Regards




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default I get two copies of pictures in the loop instead of one - why?

Good point, but I don't think that's the problem. Actually, I let the
Worksheet_Activate Sub call the "CopyChart" Sub, but I have a
EnableEvent=False before so it shouldn't happen two times beacause of that.

When I pace through the code in debugging mode, it just seem continue
pasting in double...could it be that it continue to copy paste the pictures
it just has created? Stupid of it, in that case, within the same Each...Next
loop!

When pacing through, I can't see if it actually copy the new created
pictures or the chartobjects.

/Regards


"Tom Ogilvy" skrev i meddelandet
...
What triggers your macro? Maybe you are running it twice.

--
Regards,
Tom Ogilvy

"Maria High" wrote in message
...
Hi,

I have a sheet where I in Worksheet_Activate copy all chartobjects and

paste
them as pictures and then hide the chartobjects. This make the users not
able to ruin the references in the charts.

Problem: I get two copies of pictures...why????

She sheet1 had to have a couple of charts. Code:

Sub CopyChart()
Dim chtobj As ChartObject
Dim W As Double
Dim H As Double
Dim T As Double
Dim L As Double

ActiveSheet.Unprotect
ActiveSheet.Pictures.Delete

For Each chtobj In Sheet1.ChartObjects
W = chtobj.Width
H = chtobj.Height
L = chtobj.Left
T = chtobj.Top
chtobj.CopyPicture Appearance:=xlScreen, Format:=xlPicture

ActiveSheet.Pictures.Paste.Select
With Selection
.Width = W
.Height = H
.Left = L
.Top = T
End With
Next chtobj

ActiveSheet.ChartObjects.Visible = False
Exit Sub

/Regards






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default I get two copies of pictures in the loop instead of one - why?

I ran your code and it only created one copy of each chartobject. I ran it
again and same result. Only one copy of each chart object.

xl97.

--
Regards,
Tom Ogivy



"Maria High" wrote in message
...
Good point, but I don't think that's the problem. Actually, I let the
Worksheet_Activate Sub call the "CopyChart" Sub, but I have a
EnableEvent=False before so it shouldn't happen two times beacause of

that.

When I pace through the code in debugging mode, it just seem continue
pasting in double...could it be that it continue to copy paste the

pictures
it just has created? Stupid of it, in that case, within the same

Each...Next
loop!

When pacing through, I can't see if it actually copy the new created
pictures or the chartobjects.

/Regards


"Tom Ogilvy" skrev i meddelandet
...
What triggers your macro? Maybe you are running it twice.

--
Regards,
Tom Ogilvy

"Maria High" wrote in message
...
Hi,

I have a sheet where I in Worksheet_Activate copy all chartobjects and

paste
them as pictures and then hide the chartobjects. This make the users

not
able to ruin the references in the charts.

Problem: I get two copies of pictures...why????

She sheet1 had to have a couple of charts. Code:

Sub CopyChart()
Dim chtobj As ChartObject
Dim W As Double
Dim H As Double
Dim T As Double
Dim L As Double

ActiveSheet.Unprotect
ActiveSheet.Pictures.Delete

For Each chtobj In Sheet1.ChartObjects
W = chtobj.Width
H = chtobj.Height
L = chtobj.Left
T = chtobj.Top
chtobj.CopyPicture Appearance:=xlScreen, Format:=xlPicture

ActiveSheet.Pictures.Paste.Select
With Selection
.Width = W
.Height = H
.Left = L
.Top = T
End With
Next chtobj

ActiveSheet.ChartObjects.Visible = False
Exit Sub

/Regards








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
How do you export pictures from my pictures file into a word docu Becky New Users to Excel 1 November 20th 09 07:02 PM
Number of copies to print keep defaulting to 12 copies why? Boski Excel Worksheet Functions 1 October 8th 09 05:33 PM
Storing Clip Art pictures in My Pictures folder jfg Excel Discussion (Misc queries) 4 August 10th 07 06:12 AM
Excel's Compress Pictures or deleting pictures doesn't seem work guidod Excel Discussion (Misc queries) 1 January 29th 06 06:51 AM
HELP!!!! Can't stop a loop (NOT an infinite loop) TBA[_2_] Excel Programming 3 December 14th 03 03:33 PM


All times are GMT +1. The time now is 03:28 PM.

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"