Home » excel » excel vba – set shapes name after specialpaste?

excel vba – set shapes name after specialpaste?

Posted by: admin May 14, 2020 Leave a comment

Questions:

How do I set the shapes name after specialpaste?

Here’s my codes.

With Sheets("sheet1")
  .Shapes("testpic").Copy
  .PasteSpecial Format:=xlBitmap
End With

How to set the new picture’s name, as well as location(.top,.left,etc.)

How to&Answers:

When you add a shape, it has the highest index, so:

Sub CopyShape()
Dim ws As Excel.Worksheet

Set ws = Sheets("sheet1")
With ws
    .Shapes("testpic").Copy
    .PasteSpecial Format:=xlBitmap
    With .Shapes(.Shapes.Count)
        .Name = "myName"
        .Top = 100
        'etc.
    End With
End With
End Sub