changing the protection options

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i had posted an earlier question about how to open a worksheet and not being able to select unlocked cells. i was given this code
Option Explici
Sub auto_open(
With Worksheets("sheet1"
.Unprotect Password:="hi
.EnableSelection = xlUnlockedCell
.Protect Password:="hi
End Wit
End Su

it works good. however only for one sheet, the other sheets on the workbook dont get protected, ive tried many different methods but cannot get it
 
Hi Jeff
you may cycle through all worksheets 8assumption: all have the same
password):

Option Explicit
Sub auto_open()
Dim wks as worksheet
for each wks in activeworkbook.worksheets
With wks
.Unprotect Password:="hi"
.EnableSelection = xlUnlockedCells
.Protect Password:="hi"
End With
next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

jeff said:
i had posted an earlier question about how to open a worksheet and
not being able to select unlocked cells. i was given this code:
Option Explicit
Sub auto_open()
With Worksheets("sheet1")
.Unprotect Password:="hi"
.EnableSelection = xlUnlockedCells
.Protect Password:="hi"
End With
End Sub

it works good. however only for one sheet, the other sheets on the
workbook dont get protected, ive tried many different methods but
cannot get it
 
I have found some strange behavior when protecting non-active sheets in the
workbook open event (haven't tried it with auto_open). You might want to
use this if you have problems.

Option Explicit
Sub auto_open()
Dim wks as worksheet
Dim sh as worksheet
set sh = Activesheet
Application.ScreenUpdating = False
for each wks in activeworkbook.worksheets
With wks
.Activate
.Unprotect Password:="hi"
.EnableSelection = xlUnlockedCells
.Protect Password:="hi"
End With
next
sh.Activate
Application.ScreenUpdating = True
End Sub

--
Regards,
Tom Ogilvy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top