Hi guys,

I currently have the following code in every sheet in my workbook. When someone was helping me with something else they questioned why I have this in the worksheet as it would never execute.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveSheet.Unprotect
        ActiveSheet.Protect DrawingObjects:=False, contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
        AllowUsingPivotTables:=True
    ActiveSheet.EnableSelection = xlUnlockedCells

End Sub
I then searched for an answer to how to protect all sheets with 1 code and came across this

Sub ProtectAll()
Dim ws As Worksheet
Dim S As Object
Dim pWord1 As String, pWord2 As String

pWord1 = InputBox("Please Enter the password")
If pWord1 = "" Then Exit Sub
pWord2 = InputBox("Please re-enter the password")
If pWord2 = "" Then Exit Sub

' make certain passwords are identical
If InStr(1, pWord2, pWord1, 0) = 0 Or _
InStr(1, pWord1, pWord2, 0) = 0 Then
MsgBox "You entered different passwords. No action taken"
Exit Sub
End If

For Each ws In Worksheets
ws.Protect Password:=pWord1

Next ws
For Each ws In Worksheets
ws.Protect DrawingObjects:=False, contents:=True, Scenarios:= _
        False, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
        AllowFormattingRows:=True, AllowSorting:=True, AllowFiltering:=True, _
        AllowUsingPivotTables:=True
        Next ws
As you can see this allows for a password to be input into the protection which I would like. My 2 questions are, is there somewhere on this code that you type what you would like the password to be? I thought it might be here

pWord1 = InputBox("Please Enter the password")
If pWord1 = "password" Then Exit Sub
pWord2 = InputBox("Please re-enter the password")
If pWord2 = "password" Then Exit Sub
but that didn't seem to work and also where do I stick this code. I guessed it was in a module which I did and deleted the first code from each individual sheet but it didn't seem to work.