JackDanIce
Well-known Member
- Joined
- Feb 3, 2010
- Messages
- 9,907
- Office Version
- 365
- Platform
- Windows
Hi,
I have a complex macro that imports data into a master file and creates output files.
Part of the requirement is for the output files to have 3 interactive graphs linked to pivot tables also created in the output files. The Master file contains the chart object that I copy and paste into the output file before breaking links and linking to the data in the output file only.
The macro creates 5 or 6 output files, depending on the input data. I find when the macro first runs, it creates all output files correctly. However, if I try to run it again (and the same problem occurs on another User's PC, though on their first rather than subsequent attempt), it crashes at the point of pasting the chart object.
This is the code including line (red) it errors on, it is always on this line (i.e. after Chart1.Copy). I know it's not the full code:
This is called from a loop in another procedure (from another module), the variables being passed are correct. As explained, it runs fine for the first two generated output files (i.e. for the first 2 loop iterations), but then errors on the highlighted line. However, this doesn't happen every time I run the macro, usually it occurs after the first attempt. I am also using Application.CutCopyMode = False to clear the clipboard before anything is copied and after each paste.
Apart from writing code to generate the initial chart for the Master file (rather than use the existing chart in the Master file) and then re-use that script to generate charts for the output files, can anyone suggest how a workaround for this problem? I am unable to post the full .xlsm file.
Also, I am aware to avoid using .Select and .Activate but for the code above, I couldn't get it to work at all when I wasn't using this.
Thanks in advance,
Jack
I have a complex macro that imports data into a master file and creates output files.
Part of the requirement is for the output files to have 3 interactive graphs linked to pivot tables also created in the output files. The Master file contains the chart object that I copy and paste into the output file before breaking links and linking to the data in the output file only.
The macro creates 5 or 6 output files, depending on the input data. I find when the macro first runs, it creates all output files correctly. However, if I try to run it again (and the same problem occurs on another User's PC, though on their first rather than subsequent attempt), it crashes at the point of pasting the chart object.
This is the code including line (red) it errors on, it is always on this line (i.e. after Chart1.Copy). I know it's not the full code:
Rich (BB code):
Application.CutCopyMode = False
oChart1.Copy
'wkb.Activate
With Sheets(PvtTable4)
.Select
ActiveSheet.Paste
End With
Application.CutCopyMode = False
oChart2.Copy
'wkb.Activate
With Sheets(PvtTable5)
.Select
ActiveSheet.Paste
oChart3.Copy
ActiveSheet.Paste
End With
Application.CutCopyMode = False
This is called from a loop in another procedure (from another module), the variables being passed are correct. As explained, it runs fine for the first two generated output files (i.e. for the first 2 loop iterations), but then errors on the highlighted line. However, this doesn't happen every time I run the macro, usually it occurs after the first attempt. I am also using Application.CutCopyMode = False to clear the clipboard before anything is copied and after each paste.
Apart from writing code to generate the initial chart for the Master file (rather than use the existing chart in the Master file) and then re-use that script to generate charts for the output files, can anyone suggest how a workaround for this problem? I am unable to post the full .xlsm file.
Also, I am aware to avoid using .Select and .Activate but for the code above, I couldn't get it to work at all when I wasn't using this.
Thanks in advance,
Jack