How to Hide an Excel Button Automatically When a Workbook Opens
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.

- 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.
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.
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.
Press Alt + F11 on your keyboard to open the VBA Editor.
In the Project Explorer pane on the left, double-click on 'ThisWorkbook' under your specific workbook project.
Paste the following code into the code window: Private Sub Workbook_Open() Worksheets("Sheet1").Shapes("Button 1").Visible = False End Sub
Replace 'Sheet1' and 'Button 1' with your actual worksheet name and button name. Save the file as an Excel Macro-Enabled Workbook (.xlsm).

Hide Before Saving as a Fallback
If users might open the file with macros disabled, the Workbook_Open event will fail to hide the button. Hiding the button before saving ensures it is already hidden when the file is opened.
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. Open your Workbook in WPS Spreadsheet: Launch WPS Office and open your .xlsm file.
- 2. Access the Developer Tools: Navigate to the Developer tab on the ribbon and click on the 'Visual Basic' icon.
- 3. Insert the Startup Code: Double-click 'ThisWorkbook' in the Project Explorer and paste your Workbook_Open code to hide the button.
- 4. Save and Test: Save the changes and reopen the workbook in WPS Spreadsheet to see the button hide automatically.

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




