Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Protecting excel file

Status
Not open for further replies.

jondel81

Technical User
Jul 27, 2003
71
US
I know how to protect a sheet. But am having problems protecting the entire workbook. I don't want to have to protect each sheet one-by-one.
Under the menu [Tools > Protection] There is a command to protect worksheet, but it apears not to work, even after I save and quit the program, come back in I can still edit the file.

Running MS Excel 2002 SP-1
 
Try the following, and just change the password to whatever you want it to be :-

Public Sub ToggleProtect()

Const PWORD As String = "ken"
Dim wkSht As Worksheet
Dim statStr As String
Ans = InputBox("If Unprotecting Sheets, then enter correct Password Please" & vbCrLf &
vbCrLf & _
"Else hit enter - Sheets will be saved with Default Password ")

For Each wkSht In ActiveWorkbook.Worksheets
With wkSht
statStr = statStr & vbNewLine & "Sheet " & .Name
If .ProtectContents Then
wkSht.Unprotect Password:=Ans
statStr = statStr & ": Unprotected"
Else
wkSht.Protect Password:=PWORD
statStr = statStr & ": Protected"
End If
End With
Next wkSht
MsgBox Mid(statStr, 2)
End Sub

Regards
Ken...........
 
Worksheet protection will not work unless the cells are locked.

If you are protecting your worksheets and you can still edit the cells afterwards, you may need to format the cells you want to protect so that the protection is enabled.

Unprotect the worksheet. Highlight the cells you want to protect. Select Format > Cells and click on the Protection Tab. Checkmark the Locked box. (I always check the Hidden box too, so that the end-users aren't distracted by the formulas.) Protect the worksheet.

Good Luck,
Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top