Protect/Unprotect workbook

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
 
R

rohit

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
 
D

Dave Peterson

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
 

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

Top