How to copy a picture from one shape to another

ACommandLineKindaGuy

Active Member
Joined
May 11, 2002
Messages
378
Office Version
  1. 365
Platform
  1. Windows
I would like to replace 45 icons looping n = 1 to 45
using Worksheets("Print Label").Shapes.Range(Array("Icon " & n))
with another picture Worksheets("Print Label").Shapes.Range(Array("Choice"))

I tried using the macro recorder to copy the selected shape and then right-click on the shape to be pasted, selected change picture, and selected from clipboard. But none of that was captured by the recorder

Can anyone help?

TIA John
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
From rooting around the internet, it doesn't seem like you can change the picture. But, the code below will delete all of your icon shapes and replace it with a picture from somewhere on your computer stored in the PicPath variable. Let me know if this does what you are looking for.

Code:
Sub shps()
Dim ws As Worksheet: Set ws = Sheets("Print Label")
Dim PicPath As String: PicPath = "C:\Users\UserName\Pictures\YourPicture.png"
Dim shp As Object


For Each shp In ws.DrawingObjects
    If shp.Name Like "Icon [0-9]" Then
        With Pictures.Insert(PicPath)
            .Height = shp.Height
            .Width = shp.Width
            .Top = shp.Top
            .Left = shp.Left
        End With
        shp.Delete
    End If
Next shp


End Sub
 
Upvote 0
Hi lrobbo314,

Just wanted to point out that you forgot to qualify your reference...

Code:
With [COLOR=#ff0000]ws.[/COLOR]Pictures.Insert(PicPath)

Cheers!
 
Upvote 0
Here's another way...

Code:
    Dim n As Long    
    With Worksheets("Print Label")
        .Shapes("Choice").PickUp
        For n = 1 To 45
            .Shapes("Icon " & n).Apply
        Next n
    End With

However, this method will also copy any other formatting that you may have applied to Choice.

Hope this helps!
 
Last edited:
Upvote 0
I like not having to copy an image file, but the pickup/apply method doesn't work--it only copies the formatting, not the image itself.

Any other ideas?
 
Upvote 0
Sorry, I thought we were dealing with shapes (ie. circle, rectangle, et.). I guess this is not the case, correct?
 
Upvote 0
Is the TypeName() for each of the shapes "Picture"? You can test each by selecting them and running:
Code:
Msgbox typename(Selection)
 
Upvote 0
How about this?

Code:
Sub shps()
Dim ws As Worksheet: Set ws = Sheets("Print Label")
Dim rep As Object: Set rep = ws.Shapes.Range(Array("Choice"))
Dim shp As Object

rep.Copy

For Each shp In ws.DrawingObjects
    If shp.Name Like "Icon [0-9]" Then
        ws.Pictures.Paste.Select
        With Selection
            .Height = shp.Height
            .Width = shp.Width
            .Top = shp.Top
            .Left = shp.Left
        End With
        shp.Delete
    End If
Next shp

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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