Protect/Unprotect workbook

  • Thread starter Thread starter Vitordf
  • Start date Start date
V

Vitordf

Hi,

My apologies if this is a repeat request, but I couldn't find any answers
for my dilema.

I can write the VB to protect the complete workbook, however I just want to
protect 4 out of ten worksheets, despite that all worksheets are hidden for
start bar 1 (Main).

I was wondering if there is anyone there which could help me.

Many Thanks in advance
 
The following macro will help in protecting the first 4 worksheets:

Sub Macro1()

Dim i As Integer

Sheets("Sheet1").Select

For i = 1 To 4

Range("A1").Select
ActiveSheet.Protect
ActiveSheet.Next.Select

Next i

End Sub

Cheers
Rohit
 
Can you supply the namess of the worksheets?

Option Explicit
Sub testme()
Dim iCtr As Long
Dim NameList As Variant

NameList = Array("sheet1", "sheet3", "sheet99", "Sheet107")

For iCtr = LBound(NameList) To UBound(NameList)
Sheets(NameList(iCtr)).Protect Password:="Wantapasswordtoo"
Next iCtr

End Sub
 
Back
Top