Hide selective sheets with password

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hi Guys,
I have 6 sheets in my excel workbook. I would like 2 particular sheets to be very hidden and can be opened only by password.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Change the two sheet names and password to suit your needs.
VBA Code:
Sub HideSheets()
    Dim ws As Worksheet
    For Each ws In Sheets(Array("Sheet1", "Sheet2"))
        ws.Protect Password:="MyPassword"
        ws.Visible = xlSheetVeryHidden
    Next ws
End Sub
 
Upvote 0
Solution
Sub HideSheets()

Dim ws As Worksheet

For Each ws In Sheets(Array("DD List", "IP"))

ws.Protect Password:="12345678"

ws.Visible = xlSheetVeryHidden

Next ws

End Sub


I am getting an error. Run-time error '1004';
Method 'protect' of object'_ worksheet/ failed
 
Upvote 0
Now its working.
ws.Protect Password:=12345678
As the password was a number I didn't have to write it between inverted commas.
Thanks Mumps
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top