Force Worksheet to be Protected before saving

philipgabe

New Member
Joined
Jul 29, 2011
Messages
2
I would like a macro that forces a worksheet to be protected before it can be saved. Does anyone have such a macro?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Good night!


i have an example that might help you.

Dim senha As String

senha = TextBox1.Value

Select Case senha

Case "123"
ActiveWorkbook.Unprotect ("123")
Sheets("Plan1").Visible = True
.
.
.
Case "456"
ActiveWorkbook.Unprotect ("123")
Sheets("Plan4").Visible = True
.
.
.

End Select

Att..
 
Upvote 0
I would like a macro that forces a worksheet to be protected before it can be saved. Does anyone have such a macro?
Welcome to the MrExcel board!

It is the workbook that is saved. Worksheets are just what makes up the workbook. Perhaps you only have one worksheet in your workbook?

In any case, try something like this in a copy of your workbook. The code needs to go in the 'ThisWorkbook' module. Post back if you need more help.

Change the sheet name and password to suit or you can remove the password part completely.

<font face=Courier New><br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> Workbook_BeforeSave(<SPAN style="color:#00007F">ByVal</SPAN> SaveAsUI <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>, Cancel As <SPAN style="color:#00007F">Boolean</SPAN>)<br>    Sheets("Sheet2").Protect Password:="abc"<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br><br></FONT>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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