vba code for Paste Charts as pictures erroring out

Juno123

New Member
Joined
Jun 21, 2011
Messages
10
Sub Test()
Dim ChObj As ChartObject
Dim wsReport As Worksheet
Dim Top As Double
Dim Left As Double
Application.ScreenUpdating = False
Set wsReport = Worksheets("ReportSheet")
For Each ChObj In wsReport.ChartObjects
Top = ChObj.Top
Left = ChObj.Left
ChObj.Cut
wsReport.Pictures.Paste.Select
Selection.Top = Top
Selection.Left = Left
Next ChObj
Range("A1").Select
Application.ScreenUpdating = True
End Sub

This macro code is failing with the following error-

Unable to set the Top property of the Range class

Can someone please help me with this, Its very critical for me.

Thanks in advance.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Your code worked perfectly for me in Excel 2003. The TypeName of Selection is a Picture not a Range, so I don't see how you can get that error.
 
Upvote 0
This worked for me with a few charts, if what you are trying to do is replace all the charts with pictures that is.

It doesn't use Selection which might be the problem with your code.
Code:
Option Explicit

Sub Test()
Dim ChObj As ChartObject
Dim wsReport As Worksheet
Dim chTop As Double
Dim chLeft As Double
Dim chName As String
 
    Application.ScreenUpdating = False

    Set wsReport = Worksheets("ReportSheet")

    For Each ChObj In wsReport.ChartObjects
    
        chTop = ChObj.Top
        
        chLeft = ChObj.Left
        
        chName = ChObj.Name
        
        ChObj.CopyPicture xlScreen
        
        wsReport.Paste
        
        ChObj.Delete
        
        wsReport.Shapes(wsReport.Shapes.Count).Name = chName
        
        wsReport.Shapes(chName).Top = chTop
        
        wsReport.Shapes(chName).Left = chLeft
        
    Next ChObj
 
    Application.ScreenUpdating = True

End Sub
 
Upvote 0
As mentioned in your other post (please try not to duplicate them):
Code:
With wsReport.Pictures.Paste
   .Top = Top
   .Left = Left
End With
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

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
Back
Top