delete routine after its run

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
1,762
how do i delete a button and sub routine after it has run. actually, i want to remove it from the workbook it creates, not from the template it is in. background: the code creates a new workbook and names it similarly to the original. I would like to include something to NOT copy the command button and routine across into the new workbook. any ideas?
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
1,762
i just used the macro recorder to delete the button itself and then pasted the code "ActiveSheet.Shapes("CommandButton1").Select
Selection.Delete" into my routine before it saves the new workbook. seems to work ok. cheers.
 

Smitty

Legend
Joined
May 15, 2003
Messages
29,536
If there's a chance the button will be on a sheet other than the activesheet, you might want to refer to it specifically:

Code:
Sheets("Sheet1").Shapes("CommandButton1").Delete

Note the Select/Selection part can be eliminated altogether.

Smitty
 

Watch MrExcel Video

Forum statistics

Threads
1,109,542
Messages
5,529,454
Members
409,878
Latest member
DDhol
Top