Copying picture objects from 1 workbook to another

lrutt

Board Regular
Joined
Jan 12, 2016
Messages
103
I am at a loss. I've tried all examples I've found on this site and others but still can not determine if an object exists and if so, copy to the same sheet and location in another workbook.

I have this version which works great if the object is there to copy. Problem is I need the code to determine if it's there or not and if not move on. And also target a specifically named object that I insert. I can't always assume it will be "Picture 10" so I name it "Logo" when I embed it.

Code:
Set targetsheet = Targetbook.Sheets("workbook_cover")
Set sourcesheet = Sourcebook.Sheets("workbook_cover")
Set shp = sourcesheet.Shapes("PICTURE 10")
    shp.Copy
    With targetsheet
       .Paste
        With .Shapes(.Shapes.count)
            .Left = shp.Left
            .Top = shp.Top
        End With
    End With

I've tried If statements to determine if "Logo" is nothing but it just stops there and does not move on. I've seen dozens of examples I've tried but nothing works for some reason. I know the object is there and labeled "Logo" as I can click on it and that's what shows in the name field.

Any help would be appreciated.

Thanks
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,452
Try...

Code:
[color=darkblue]Set[/color] targetsheet = Targetbook.Sheets("workbook_cover")
[color=darkblue]Set[/color] sourcesheet = Sourcebook.Sheets("workbook_cover")

[color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] [color=darkblue]Next[/color]
[color=darkblue]Set[/color] shp = sourcesheet.Shapes("Logo")
[color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]GoTo[/color] 0
[color=darkblue]If[/color] [color=darkblue]Not[/color] shp [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
    shp.Copy
    [color=darkblue]With[/color] targetsheet
       .Paste
        [color=darkblue]With[/color] .Shapes(.Shapes.Count)
            .Left = shp.Left
            .Top = shp.Top
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]Else[/color]
    MsgBox "The shape/object does not exist.", vbExclamation
[color=darkblue]End[/color] [color=darkblue]If[/color]

Hope this helps!
 

lrutt

Board Regular
Joined
Jan 12, 2016
Messages
103
woohoo, that did it.

Odd statement....if not shp is nothing then. A double negative. I always tried it as a.....if shp = "logo" type statement.

Thanks.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,888
Messages
5,621,430
Members
415,839
Latest member
Pollydooner

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
Top