logo
search
VBA & Macro Problems

How to Hide an Excel Button Automatically When a Workbook Opens

Chanuka GeekiyanageChanuka Geekiyanage Oct 22, 2026 868 views

Question details

The user needs to automatically hide a specific button or form control on an Excel worksheet as soon as the workbook is opened.

How to Hide an Excel Button When the Workbook Opens
Product
Excel
Device & OS
not provided
Scenario
Automating worksheet UI elements so that a control button is hidden from the user upon file startup.
Observed behavior
By default, the button remains visible upon opening unless manually hidden or programmatically controlled by a startup macro.
Before you start

Verify the exact name of the button and the worksheet it resides on. Ensure your workbook is saved as a Macro-Enabled Workbook (.xlsm) to allow VBA code to run automatically upon opening.

Solution 1Recommended

Use the Workbook_Open VBA Event

Add a simple VBA macro to the ThisWorkbook module that triggers automatically every time the file is opened.

The most direct way to control objects upon startup is by using the Workbook_Open event. This code runs immediately when the workbook is opened, provided that the user has enabled macros.

1
Open the Visual Basic Editor

Press Alt + F11 on your keyboard to open the VBA Editor.

2
Locate ThisWorkbook

In the Project Explorer pane on the left, double-click on 'ThisWorkbook' under your specific workbook project.

3
Enter the VBA Code

Paste the following code into the code window: Private Sub Workbook_Open() Worksheets("Sheet1").Shapes("Button 1").Visible = False End Sub

4
Customize and Save

Replace 'Sheet1' and 'Button 1' with your actual worksheet name and button name. Save the file as an Excel Macro-Enabled Workbook (.xlsm).

Use the Workbook_Open VBA Event
Macro Security Requirement: The macro must be enabled by the user when opening the file for this code to execute. If macros are disabled, the button will remain visible.

Run VBA Macros Seamlessly in WPS Spreadsheet

WPS Office provides excellent support for Excel VBA macros, allowing you to automate tasks and control form objects smoothly. You can easily insert, edit, and run startup macros just as you would in Microsoft Excel.

  1. 1. Open your Workbook in WPS Spreadsheet: Launch WPS Office and open your .xlsm file.
  2. 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on the 'Visual Basic' icon.
  3. 3. Insert the Startup Code: Double-click 'ThisWorkbook' in the Project Explorer and paste your Workbook_Open code to hide the button.
  4. 4. Save and Test: Save the changes and reopen the workbook in WPS Spreadsheet to see the button hide automatically.
Fully compatible with Microsoft Excel .xlsm and .xlsb formatsBuilt-in Visual Basic Editor for writing and editing macrosLightweight application with fast startup timesFree to download and easy to install
microsoft office alternative - wps office

Frequently Asked Questions

How do I find the exact name of my button in Excel?

Right-click or Ctrl-click on the button to select it, then look at the Name Box located to the left of the formula bar. The name displayed there (e.g., 'Button 1') is the exact name you need to use in your VBA code.

Why isn't my Workbook_Open macro running when I open the file?

Macros might be disabled in your security settings. Go to your macro security settings and ensure that macros are enabled, or make sure the file is saved in a Trusted Location. Additionally, ensure the file is saved as an .xlsm format.

Can I hide an ActiveX command button using the same VBA code?

Yes, the code to hide an ActiveX command button is similar, but you refer to the OLEObject instead of the Shape, or simply call the object directly by its codename, such as `Sheet1.CommandButton1.Visible = False`.