Removing picture from a worksheet

J

James

Hi All,

I have about 90 different worksheets and majority of worksheets have a
imagine file called 'picture 1'.

All I am trying to do is delete this picture from every worksheets. So
far I've done:



For Each ws In ThisWorkbook.Worksheets

Set DelPic = ws.Shapes("Picture 1")
'DelPic.Delete

Next


This macro runs fine if there is a picture 1 in the worksheet but
because some of the worksheets don't really have a picture. It creates
an error. How do I condition it so it only deletes 'picture 1' if
there is one in the worksheet?

Thank you so much


Regards


James
 
W

Walter Briscoe

In message <[email protected]
s.com> of Sun, 14 Feb 2010 21:47:24 in microsoft.public.excel.programmin
g said:
Hi All,

I have about 90 different worksheets and majority of worksheets have a
imagine file called 'picture 1'.

All I am trying to do is delete this picture from every worksheets. So
far I've done:



For Each ws In ThisWorkbook.Worksheets

Set DelPic = ws.Shapes("Picture 1")
'DelPic.Delete

Next


This macro runs fine if there is a picture 1 in the worksheet but
because some of the worksheets don't really have a picture. It creates
an error. How do I condition it so it only deletes 'picture 1' if
there is one in the worksheet?

You might try:
On Error Resume Next ' Ignore ALL errors
For Each ws In ThisWorkbook.Worksheets
ws.Shapes("Picture 1").Delete ' Try merging Set and Delete
Next ws
On Error GoTo 0 ' Restore default error handling
 
R

Rick Rothstein

Here is a method to do this without error checking...

Dim WS As Worksheet, SH As Shape
.......
.......
For Each WS In ThisWorkbook.Worksheets
For Each SH In WS.Shapes
If SH.Name = "Picture 1" Then
SH.Delete
Exit For
End If
Next
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top