Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to know if buttons exist

Status
Not open for further replies.

denis60

Technical User
Apr 19, 2001
89
CA
How do i check, when i open my worksheet in excel, if all my buttons (on my sheet) are still there and if not add them
 
Hey,

If you know the button name. Then you can do a dummy check on the button. FOr example if you have a button called MyButton on the sheet Hello then :

msgbox Worksheets("Hello").MyButton

will do one of two things.
If it exists then it will display true/false.
if it does not exist you get on error.

So you could do this

Dim DummyString as string

on error goto createButton
dummystring=Worksheets("Hello").MyButton

createButton:
'write the code to create your new button here.


Hope this helps,
krupa





 
To check for the command buttons you can use the following to print the names the immediate window. If you know the names of the buttons.

Code:
For Each cmd In ActiveSheet.Shapes
    Debug.Print cmd.Name
Next

After determining which buttons are there, you can add teh buttons that are not. If you need more assistance with this, let me know.

Dave
 
Thanks folks, yours exemples works good. Your the bests
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top