Replace Picture on all sheets

PCTech

Board Regular
Joined
Mar 24, 2005
Messages
215
Is there a way to loop through all sheets and if it finds Picture 2 delete it and insert a new picture. The following does not loop to the next sheet.

Code:
 On Error Resume Next
    For Each vs In ActiveWorkbook.Worksheets
    ActiveSheet.Shapes("Picture 2").Select
    Selection.Delete
    Range("A1").Select
    ActiveSheet.Pictures.Insert("Y:\Work Files\PRICE GUIDE\marquispb.jpg").Select
Next

Thanks,
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try

Code:
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
    ws.Shapes("Picture 2").Delete
    ws.Pictures.Insert ("Y:\Work Files\PRICE GUIDE\marquispb.jpg")
    With ws.Shapes(ws.Shapes.Count)
        .Top = ws.Range("A1").Top
        .Left = ws.Range("A1").Left
    End With
Next ws
 
Upvote 0
Awesome, It does what I needed it to do. Now I have another issue. Some sheets have a different picture that is also referenced as "Picture 2". (Two "Picture2"'s on the same sheet?) Is there a way to tell this to delete the picture in the upper left corner? Or is there a way to change the name of the other picture to "Picture 20" or something else? I would have to do that manually.
 
Upvote 0
Are you sure? As far as I know you can only have one "Picture 2" on a worksheet. Could the other one be "Picture2" or similar?
 
Upvote 0
I have taken care of the previous issue. Now can someone tell me why this line does not work in my code.
Code:
 If ws.Shapes("Picture 2").exist Then
It acts like Picture 2 is on every sheet.
Code:
Sub MarquisLogo()
Dim vs As Worksheet
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
    If ws.Shapes("Picture 2").exist Then
    ws.Shapes("Picture 2").Delete
    ws.Pictures.Insert ("Y:\Work Files\PRICE GUIDE\marquispb.jpg")
    With ws.Shapes(ws.Shapes.Count)
        .Top = ws.Range("A1").Top
        .Left = ws.Range("A1").Left
        .LockAspectRatio = msoFalse
        .Height = 114#
        .Width = 222.75
    End With
    Else
    End If
Next ws
End Sub
 
Upvote 0
I found a way to make it work.
Code:
Sub MarquisLogo()
Dim vs As Worksheet
On Error Resume Next
For Each ws In ActiveWorkbook.Worksheets
    For i = 1 To ws.Shapes.Count
    If ws.Shapes(i).Name = "Picture 2" Then
        ws.Shapes(i).Delete
        ws.Pictures.Insert ("Y:\Work Files\PRICE GUIDE\marquispb.jpg")
    With ws.Shapes(ws.Shapes.Count)
        .Top = ws.Range("A1").Top
        .Left = ws.Range("A1").Left
        .LockAspectRatio = msoFalse
        .Height = 114#
        .Width = 222.75
    End With
    Else
    End If
Next i
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,361
Members
449,080
Latest member
Armadillos

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