VBA & Macro Problems

How to Fix Unable to Set Worksheet Visible Property Error in Excel VBA

John WilsonJohn Wilson Oct 26, 2026 869 views

Question details

The user encounters an error when trying to change a hidden worksheet's visibility using Excel VBA.

How to Fix 'Unable to Set Worksheet Visible Property' in Excel VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
Running a VBA macro to unhide or alter the visibility status of a worksheet to xlSheetVisible.
Observed behavior
Excel returns a runtime error stating it is unable to set the Visible property of the Worksheet class, typically caused by the workbook structure being protected.
Before you start

Verify if your Excel workbook is password protected, as structural protection locks sheet visibility settings and prevents VBA from executing modifications.

Solution 1Recommended

Remove Workbook Structure Protection

Unprotecting the workbook structure removes the lock on worksheets, allowing VBA to successfully change the sheet visibility settings.

The 'Unable to set the Visible property' error occurs because the workbook's structure is locked. When the structure is protected, users and macros are prevented from hiding, unhiding, moving, or deleting sheets. Removing this protection resolves the VBA execution error.

1
Open the Review Tab

Open your macro-enabled Excel file and navigate to the 'Review' tab located on the top ribbon.

2
Unprotect Workbook

Click on the 'Protect Workbook' or 'Unprotect Workbook' button. If a password was previously configured, a prompt will appear.

3
Enter the Password

Type the correct workbook protection password into the prompt and click 'OK' to remove the structural lock.

4
Run the VBA Macro

Return to your VBA editor or trigger your macro again to successfully set the worksheet visibility to 'xlSheetVisible'.

Remove Workbook Structure Protection
Worksheet vs. Workbook Protection: Note that worksheet protection (which locks cell contents) is entirely different from workbook protection (which locks the sheet structure). You must disable workbook protection to fix this specific VBA error.
Advanced Spreadsheet Tool

Easily Manage Workbook Protection and VBA Macros in WPS Office

WPS Spreadsheets provides robust support for VBA macros and workbook protection. You can easily manage sheet visibility, execute your VBA code smoothly, and secure your files without compatibility issues.

  1. 1. Open your file in WPS: Launch WPS Office and open your macro-enabled spreadsheet.
  2. 2. Navigate to the Review tab: Click on the 'Review' tab in the top menu bar to access the file's security and protection features.
  3. 3. Unprotect the Workbook: Click 'Unprotect Workbook', enter your password if required, and proceed to run your VBA script to alter sheet visibility without errors.
Full compatibility with Microsoft Excel (.xlsx, .xlsm, .xls) file formats.Advanced VBA and Macro support for automating complex spreadsheet tasks.Intuitive interface for easily toggling workbook and worksheet protection.
microsoft office alternative - wps office

Frequently Asked Questions

Why does VBA throw a 1004 runtime error when unhiding a worksheet?

Runtime error 1004 often occurs when the workbook's structure is protected. Excel prevents VBA from modifying the Visible property of a worksheet if structural changes are locked, resulting in this error.

Can I temporarily unprotect a workbook using VBA code?

Yes. You can unprotect the workbook directly within your macro by adding `ActiveWorkbook.Unprotect Password:="yourpassword"` before the visibility code, and then reprotect it using `ActiveWorkbook.Protect Password:="yourpassword"` immediately after.

What is the difference between xlSheetHidden and xlSheetVeryHidden?

Setting a sheet to `xlSheetHidden` hides the tab but allows users to unhide it manually from the Excel user interface. Setting it to `xlSheetVeryHidden` means the sheet tab is completely hidden and can only be made visible again by executing VBA code.