How to Fix Unable to Set Worksheet Visible Property Error in Excel VBA
Question details
The user encounters an error when trying to change a hidden worksheet's visibility using 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.
Verify if your Excel workbook is password protected, as structural protection locks sheet visibility settings and prevents VBA from executing modifications.
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.
Open your macro-enabled Excel file and navigate to the 'Review' tab located on the top ribbon.
Click on the 'Protect Workbook' or 'Unprotect Workbook' button. If a password was previously configured, a prompt will appear.
Type the correct workbook protection password into the prompt and click 'OK' to remove the structural lock.
Return to your VBA editor or trigger your macro again to successfully set the worksheet visibility to 'xlSheetVisible'.

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. Open your file in WPS: Launch WPS Office and open your macro-enabled spreadsheet.
- 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. Unprotect the Workbook: Click 'Unprotect Workbook', enter your password if required, and proceed to run your VBA script to alter sheet visibility without errors.

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.




