Convert a shape (group) into a picture inside wrksheet using VBA

geo77

New Member
Joined
May 26, 2009
Messages
31
I am obsessed with terse code. The code below does the job (I recorded this macro):

Sub copy_and_paste_as_picture()

ActiveSheet.Shapes.Range(Array("Group 5")).Select
Selection.Copy
ActiveSheet.Pictures.Paste

End Sub

Can someone help me clean this up and turn the three lines inside the sub into one line (preferably without selection)?
A one line conversion from a shape into a picture would be cool but that's probably not possible (I can delete the original group later anyway).

Thanks a lot!
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I think the best you could do would be this.
Code:
Sub copy_and_paste_as_picture()

    ActiveSheet.Shapes.Range(Array("Group 5")).Copy
    ActiveSheet.Pictures.Paste

End Sub
 
Upvote 0
I think the best you could do would be this.
Code:
Sub copy_and_paste_as_picture()

    ActiveSheet.Shapes.Range(Array("Group 5")).Copy
    ActiveSheet.Pictures.Paste

End Sub

That's an obvious solution and I tried it before posting this. I'm getting the error: "Object does not support this property or method. Run time error 438

It must be a one line solution. Thanks!
 
Upvote 0
Try the following instead...

Code:
Sub copy_and_paste_as_picture()

    ActiveSheet.Shapes("Group 5").Copy
    ActiveSheet.Pictures.Paste


End Sub
 
Upvote 0
Domenic, amazing, thanks, we love Canada!
I assume it cannot be converted to a one liner. Is it true?
Thanks again!!!
 
Upvote 0
Domenic, amazing, thanks, we love Canada!

Nice to hear. :-)

I assume it cannot be converted to a one liner. Is it true?

I don't think so, but it can be re-written as follows...

Code:
Sub copy_and_paste_as_picture()

    With ActiveSheet
        .Shapes("Group 5").Copy
        .Pictures.Paste
    End With


End Sub


Thanks again!!!

You're very welcome!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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