ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   verifying an object exists (https://www.excelbanter.com/excel-programming/319773-verifying-object-exists.html)

JT[_2_]

verifying an object exists
 
I have a macro with two rectangles that I use as
pushbuttons on a worksheet. Each one has a unique macro
assigned to it.

Macro # 2 makes a copy of the activeworkbook and deletes
the rectangle assigned to Macro # 2 (on the saved copy).
I don't want users to have the option of making another
copy from the "saved" copy.

No problem, so far. However when I open the "saved" copy,
Macro # 1 is used to make a copy of the data and send as
an e-mail attachment. It also deletes the 2 rectangles.

However, if I try to run Macro # 1 (from the "saved" copy,
I get an error because it is trying to delete the second
rectangle (which has already been deleted when the
workbook is copied.)

If Macro # 1 is run from the original workbook, no problem
because both rectangles still exist.

Any suggestions on code to verify the existance of
rectangle 2 would be appreciated.

As always, thanks for the help.

Robin Hammond[_2_]

verifying an object exists
 
You could just wrap the delete command in an on error resume next.

On Error Resume Next
'delete the shape
On Error Goto 0

Robin Hammond
www.enhanceddatasystems.com

"JT" wrote in message
...
I have a macro with two rectangles that I use as
pushbuttons on a worksheet. Each one has a unique macro
assigned to it.

Macro # 2 makes a copy of the activeworkbook and deletes
the rectangle assigned to Macro # 2 (on the saved copy).
I don't want users to have the option of making another
copy from the "saved" copy.

No problem, so far. However when I open the "saved" copy,
Macro # 1 is used to make a copy of the data and send as
an e-mail attachment. It also deletes the 2 rectangles.

However, if I try to run Macro # 1 (from the "saved" copy,
I get an error because it is trying to delete the second
rectangle (which has already been deleted when the
workbook is copied.)

If Macro # 1 is run from the original workbook, no problem
because both rectangles still exist.

Any suggestions on code to verify the existance of
rectangle 2 would be appreciated.

As always, thanks for the help.





All times are GMT +1. The time now is 12:02 AM.

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