Regarding password protection in Excel


Posted by Saurabh Halwawala on January 31, 2002 12:33 PM

I want Excel to ask me to specify the password every time I try to save an excel spreadsheet.
This is different than the password to open or password to modify the sheet.
I want to be able to open the sheet without any password and also modify it but as soon as I try to save the workbook, it should ask me for the password.
If anyone has any idea on this specific search...
Thanks



Posted by Tom Urtis on January 31, 2002 2:03 PM

Try this. Locate the Excel Workbook icon just to the left of the "File" menu option, near the upper left corner of your workbook screen. Right click on that icon, then left click on View Code, and paste this in.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim myPassword As String

myPassword = InputBox(prompt:="Please enter the password to save file:", _
Title:="Password is required to save this file.")

If myPassword <> "PASSWORD" Then

MsgBox prompt:="Click OK to return to Report.", _
Title:="Save cancelled -- correct password not entered", _
Buttons:=16

Cancel = True

End If

End Sub


Modify the PASSWORD to the password of your choice.


Any help?

Tom Urtis