ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Does Shape Exist? (https://www.excelbanter.com/excel-programming/368121-does-shape-exist.html)

Alan

Does Shape Exist?
 
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 ...


Ron de Bruin

Does Shape Exist?
 
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" wrote in message oups.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 ...




Chip Pearson

Does Shape Exist?
 
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" wrote in message
oups.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 ...




Alan

Does Shape Exist?
 

Thanks guys.



All times are GMT +1. The time now is 03:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com