delete routine after its run

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,005
Office Version
  1. 365
Platform
  1. Windows
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?
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top