verify a shape exists in the sheet

  • Thread starter Thread starter vandaley
  • Start date Start date
V

vandaley

Hi,

I am trying to delete a shape from a sheet with:

ActiveSheet.Shapes("AAPicture").Select
Selection.Delete

I need to verify first that the shape exists so the user wont get an
error that the object doesnt exists.

How can i do that?

Thanks,
 
Hi vandaley

One way is to use on error

On Error Resume Next
ActiveSheet.Shapes("AAPicture").Delete
On Error GoTo 0
 
Hi,

how about this one:

Dim s As Shape
For Each s In ActiveSheet.Shapes
If s.Name = "Test" Then
MsgBox "shape Test exists"
exit for
End If
Next

"Name" seems to be case sensitive.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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

Similar Threads

Shapes in 2010 1
Loop to delete shapes 8
delete a shape 2
Show shape on cell select, Hide shape when cell is deselected 5
Change Shape text / Color 3
Shape Arrays VBA 0
deselect chart 2
shape remains selected 1

Back
Top