Code to paste graphs as pictures

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
All,

I have a graph that loops through all charts on one tab and then pastes the charts as pictures on another tab.

The code keeps getting hung up on a section, but the hangup is inconsistent. In other words, sometimes the code works fine, ohter times I get an error:

"Run time error 1004"
"An invlaid character was found in text character"

The code gets hung up on the CopyPicture line found below.

The inconsistency has me wondering if there is just something with Excel that it is hanging on something. Is there a way to kind of clear out some garbage that might be hanging around. If I close Excel and re-open the file, iot works perfectly a few times and then starts hanging up.

Code:
For i = 1 To intX
        Range("A1").Select
        ActiveSheet.ChartObjects(i).Activate
        ActiveSheet.ChartObjects(i).Select
        ActiveChart.ChartArea.Select
        ActiveChart.CopyPicture Appearance:=xlPrinter, Size:=xlScreen, Format:= _
        xlPicture
        ActiveWindow.Visible = False
        'Windows("Gildan Reporting Master_V2.xls").Activate
        'ActiveChart.ChartArea.Select
        Sheets("Graphs Final").Select
        
        ''Set the paste column (A or L)
        If i Mod 2 <> 0 Then
            mypastecol = 1
        ElseIf i Mod 2 = 0 Then
            mypastecol = 12
        End If
        
        ''Set the paste row
        If i Mod 1 = 0 And i > 2 Then
            mypasterow = mypasterow + 18
        ElseIf i Mod 2 <> 0 And i < 3 Then
            mypasterow = mypasterow
        End If

        ''Finally paste the chart as a picture
        Cells(mypasterow, mypastecol).Select
        ActiveSheet.Pictures.Paste.Select
        
        Sheets("Graphs").Select
        
Next
 
Last edited by a moderator:

Some videos you may like

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,751
Maybe the clipboard is full. Also all that selection is probably not needed. Trial the following. HTH. Dave
Code:
Application.CutCopyMode = False
Next
 

Watch MrExcel Video

Forum statistics

Threads
1,126,932
Messages
5,621,682
Members
415,849
Latest member
PhoenixRising2015

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top