Set wsheet protect to Null

nashbal

New Member
Joined
Mar 3, 2010
Messages
2
Hi,

I am trying to protect a worksheet, but still enable the "Group/Ungroup" functionality to work. I've managed to source the code for this from another forum - Code below:

Sub ProtectAll()

Dim ws As Worksheet
sSheet = "Sheet7"

For Each ws In ThisWorkbook.Worksheets
Select Case ws.Name
Case sSheet7
Case Else
ws.Protect Password:="PASSWORD", userinterfaceonly:=True
ws.EnableOutlining = True
End Select
Next ws

End Sub


My issue now is that I am trying to change the password to Null so used the code:
ws.Protect Password:=Null, userinterfaceonly:=True

But unfortunately when I try to unprotect the wsheet using the blank password, it returns the message that the Password supplied is not correct. I am a newbie VBA user, so could do with some advice on how to correct this so that the worksheet is protected with a blank password.

Many thanks to anyone who can help.
 
Hi Richard, thanks for getting back so quickly. I have tried that and receive a run time error 1004 (Application or object defined error). There is also some related code which I've inserted so that the previous macro runs everytime the Excel file is opened, otherwise the previous macro didn't work anymore.

Private Sub Workbook_Open()
Call Sheet7.ProtectAll
End Sub

Any ideas which part of this is causing the issue?
 
Upvote 0

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