View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Walter Briscoe Walter Briscoe is offline
external usenet poster
 
Posts: 279
Default Removing picture from a worksheet

In message
s.com of Sun, 14 Feb 2010 21:47:24 in microsoft.public.excel.programmin
g, James writes
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
--
Walter Briscoe