Copy & Paste Shapes as Microsoft Office Drawing Object

prasush

New Member
Joined
Sep 1, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
Hello Experts,
I am trying to copy and paste shapes using VBA.
I figured out the suitable code after going through couple of forums.
Few lines of my code are as follows:

ActiveSheet.Shapes("Rectangle 203").Copy
ActiveSheet.Range("J56").Paste
Selection.ShapeRange.IncrementTop 4
Selection.ShapeRange.IncrementLeft 4
Selection.ShapeRange.Fill.Visible = msoFalse


The issue that I noticed is....the pasted shape is actually a picture. So it is not treated as Shape, so the Fill statement does not work.
If I use pastespecial command outside VBA, I need to select "Microsoft Office Drawing Object" and then it is pasted as shape. Further processing of shape like Fill is feasible with the shape.
I tried to use Macro Recorder but following line gives an error.
Range("J56").PasteSpecial Format:="Microsoft Office Drawing Object"
Error - Named Argument Not Found
It seems the code using macro recorder is not always a good solution. Please review.
Regards
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
You need to reference the worksheet, not the range object, for example . . .

VBA Code:
Worksheets("Sheet1").PasteSpecial Format:="Microsoft Office Drawing Object"

Hope this helps!
 
Upvote 0
Ciao Domenic,
Thanks for your review.

I modified as below:

Activesheet.Range("J56").PasteSpecial Format:="Microsoft Office Drawing Object"

but now I have

Run-time error '1004': Application-defined or object-defined error

Thanks for your response. Regards
 
Upvote 0
Finally, the following lines are working now:

VBA Code:
ActiveSheet.Shapes("Rectangle 203").Copy
    Range("J56").Select
    ActiveSheet.PasteSpecial Format:="Microsoft Office Drawing Object"
    Selection.ShapeRange.IncrementTop 4
    Selection.ShapeRange.IncrementLeft 5.5
    Range("O56").Select
    ActiveSheet.PasteSpecial Format:="Microsoft Office Drawing Object"
    Selection.ShapeRange.IncrementTop 4
    Selection.ShapeRange.IncrementLeft 5.5
    Selection.ShapeRange.Fill.Visible = msoFalse

Thanks for reading.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,232
Messages
6,123,765
Members
449,121
Latest member
Vamshi 8143

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