Tags: defined, delete, determine, excel, exist, exists, microsoft, msdn, rectangle, shape, software, specific, user, vba

Does Shape Exist?

On Microsoft » Microsoft Excel

1,503 words with 3 Comments; publish: Fri, 23 May 2008 02:37:00 GMT; (30662.50, « »)

Using VBA how can I determine whether a shape (e.g. a rectangle) with a

specific user defined name actually exists before I try to delete it?

thanks ...

All Comments

Leave a comment...

  • 3 Comments
    • Hi Alan

      You can use a on error

      On Error Resume Next

      'your delete code

      On Error GoTo 0

      Regards Ron de Bruin

      http://www.rondebruin.nl

      "Alan" <alan.dowen.excel.questionfor.info.virgin.net> wrote in message news:1153743254.485655.278250.excel.questionfor.info.p79g2000cwp.googlegroups.com...

      > Using VBA how can I determine whether a shape (e.g. a rectangle) with a

      > specific user defined name actually exists before I try to delete it?

      > thanks ...

      >

      #1; Fri, 23 May 2008 02:38:00 GMT
    • If you really want to test for its existence, use code like

      Dim SH As Shape

      Set SH = ActiveSheet.Shapes("MyRect")

      If Not SH Is Nothing Then

      SH.Delete

      End If

      However, it would be simple to attempt to delete the shape and

      ignore any error that occurs:

      On Error Resume Next

      ActiveSheet.Shapes("MyRect").Delete

      On Error GoTo 0

      Cordially,

      Chip Pearson

      Microsoft MVP - Excel

      Pearson Software Consulting, LLC

      www.cpearson.com

      "Alan" <alan.dowen.excel.questionfor.info.virgin.net> wrote in message

      news:1153743254.485655.278250.excel.questionfor.info.p79g2000cwp.googlegroups.com...

      > Using VBA how can I determine whether a shape (e.g. a

      > rectangle) with a

      > specific user defined name actually exists before I try to

      > delete it?

      > thanks ...

      >

      #2; Fri, 23 May 2008 02:39:00 GMT
    • Thanks guys.
      #3; Fri, 23 May 2008 02:40:00 GMT