PDA

View Full Version : Solved: Code runs on other open workbooks



wilg
08-07-2010, 07:33 AM
Hi. I have some protect worksheet codes that if I have another workbook open will protect the sheets on that workbook as well as the one this code lies within. Is there something I should do differnt to ensure the code I write only runs in the workbook I have the code? This happens with other code I use as well?



Sub ProtectAll()
Application.ScreenUpdating = False
Dim Sh As Worksheet
Dim myPassword As String
myPassword = password
For Each Sh In activeWorkbook.Worksheets
Sh.Protect Password:=myPassword

Next Sh
Sheets("sheets 1").Visible = False
Application.ScreenUpdating = True
End Sub

Bob Phillips
08-07-2010, 07:53 AM
Sub ProtectAll()
Dim Sh As Worksheet
Dim myPassword As String

Application.ScreenUpdating = False

myPassword = password

For Each Sh In ThisWorkbook.Worksheets
Sh.Protect Password:=myPassword

Next Sh
ThisWorkbook.Sheets("sheets 1").Visible = False

Application.ScreenUpdating = True
End Sub

wilg
08-07-2010, 08:02 AM
So simple but what a difference it makes......thanks sooo much.