Locking workbook on save/close???

jms493

Board Regular
Joined
Aug 6, 2003
Messages
60
I am saving a excel speadsheet on a network at work. Some people only need to view it and dont need to change anything. Some people will need to go in a change data. Problem I see is that when a person opens it up unprotects it and saves it, it doesnt prompt them to password protect it or does not do it automatically upon close.

So the next time someone opens it up it will be unprotected.

Can I get it to alway protect the worksheet upon closing witht he same password???

Thanks
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You could use something along these lines:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Dim Sh As Worksheet
    Dim myPassword As String
        myPassword = "password"
    
        For Each Sh In ActiveWorkbook.Worksheets
            Sh.Protect Password:=myPassword
        Next Sh
End Sub
The code goes in the ThisWorkbook module and will password protect each sheet when the wb is closed.

Hope that helps,

Smitty

EDIT: DOH! Sorry about that.
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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