logo
search
VBA & Macro Problems

How to Delete Specific Excel Form Buttons with VBA

Nimra MalikNimra Malik Oct 21, 2026 868 views

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.

How to Delete Specific Excel Form Buttons Using VBA
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.
Before you start

Verify whether the buttons you want to delete are Form Controls or ActiveX Controls, as the required VBA targeting method differs for each type.

Solution 1Recommended

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.

1
Identify the Button Name

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'.

2
Open the VBA Editor

Press ALT + F11 on your keyboard to open the Visual Basic for Applications (VBA) Editor.

3
Insert a New Module

Click 'Insert' from the top menu and select 'Module' to create a new space for your macro.

4
Write the Deletion Code

Enter the code: ActiveSheet.Shapes("CommandButton1").Delete (replace 'CommandButton1' with your button's exact name).

5
Run the Macro

Press F5 or click the Run button to execute the code. Only the specified button will be removed.

Delete Specific ActiveX or Form Buttons by Name
Direct Deletion: Targeting shapes directly by their name is the safest way to ensure logos and checkboxes remain untouched.

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. 1. Enable the Developer Tab: Open your file in WPS Spreadsheet, click on 'Options', and enable the Developer tab to access macro tools.
  2. 2. Open the VBA Editor: Click 'Macros' or press ALT + F11 to launch the integrated Visual Basic Editor in WPS.
  3. 3. Insert Your Code: Create a new module and paste your targeting or looping VBA code to delete the specific buttons.
  4. 4. Execute the Macro: Run your script seamlessly. WPS Spreadsheet will process the VBA code just like Excel, safely removing only the targeted shapes.
Fully compatible with Microsoft Excel VBA macros (.xlsm)Easily identify and manage Form Controls and ActiveX elementsLightweight and free alternative for complex spreadsheet automationIntuitive Developer tab and built-in Visual Basic Editor
microsoft office alternative - wps office

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.