How to Delete Specific Excel Form Buttons with VBA
Question details
The user needs to copy a worksheet to a new workbook and use VBA to delete only certain buttons while preserving other shapes like logos, checkboxes, and text boxes.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Cleaning up a worksheet for distribution by removing specific interactive buttons without wiping out all design and form elements.
- Observed behavior
- A generic shape-deletion VBA loop removes all shapes, inadvertently deleting necessary logos, checkboxes, and text boxes along with the buttons.
Verify whether the buttons you want to delete are Form Controls or ActiveX Controls, as the required VBA targeting method differs for each type.
Delete Specific ActiveX or Form Buttons by Name
Use this method when you know the exact names of the buttons you want to remove, allowing you to bypass looping and directly delete specific shapes.
Instead of looping through all shapes on the worksheet, you can pinpoint the exact button using the Shapes collection. This ensures that no other design elements, such as logos or text boxes, are accidentally deleted.
For a Form Control, right-click the button. For an ActiveX control, enable Developer > Design Mode and click the button. Note the name displayed in the Name Box (left of the formula bar), such as 'CommandButton1'.
Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.
Click 'Insert' from the top menu and select 'Module' to create a new space for your macro.
Enter the code: ActiveSheet.Shapes("CommandButton1").Delete (replace 'CommandButton1' with your button's exact name).
Press F5 or click the Run button to execute the code. Only the specified button will be removed.

Filter and Delete Only ActiveX Command Buttons
Use this method if you have multiple ActiveX buttons to remove and want to delete them programmatically without affecting Form Controls or regular shapes.
Use WPS Spreadsheet to Manage Macros and VBA Forms Easily
WPS Office provides robust support for VBA and Macros, allowing you to easily edit, run, and manage scripts to delete specific form controls in your spreadsheets while ensuring your work remains fully compatible with Microsoft Excel.
- 1. Enable the Developer Tab: Open your file in WPS Spreadsheet, click on 'Options', and enable the Developer tab to access macro tools.
- 2. Open the VBA Editor: Click 'Macros' or press ALT + F11 to launch the integrated Visual Basic Editor in WPS.
- 3. Insert Your Code: Create a new module and paste your targeting or looping VBA code to delete the specific buttons.
- 4. Execute the Macro: Run your script seamlessly. WPS Spreadsheet will process the VBA code just like Excel, safely removing only the targeted shapes.

Frequently Asked Questions
How can I find the exact name of an Excel form button?
For Form Control buttons, simply right-click the button. For ActiveX buttons, enable 'Design Mode' on the Developer tab and left-click the button. The exact name will appear in the Name Box located to the left of the formula bar.
How do I delete all Form Control buttons at once without affecting shapes?
You can use the command 'ActiveSheet.Buttons.Delete' in your VBA macro. This specific collection targets only Form Control buttons and will bypass ActiveX controls, images, logos, and text boxes entirely.
Why does my VBA code delete logos and checkboxes too?
If you use a generic loop like 'For Each shp In ActiveSheet.Shapes' and call 'shp.Delete', Excel will iterate through all shape elements, which includes images, logos, checkboxes, and text boxes. To prevent this, you must specify the exact shape name or filter the objects by their specific TypeName.




