Protect a Worksheet in Excel 97

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

Guest

I was asked to design a worksheet to perform certain calculations. It was however vital that the sheet be protected since it also includes some macros (VB code) to automate certain processes viz to add rows etc. Rows cannot be added whilst the sheet is protected
The operating system, perhaps a little outdated (Windows 95).

Question: Why do I get an error message with the basic code line to protect sheet1 : Worksheets("Sheet1").Protect Password:="ABCD"
The minute I change the code to Sheet2, the processs it completed immediately! Please help
Incidently, the above code runs beautifully on later versions, viz 98, 2000 etc. Please help. I have tried several code methods, none which seem to work
Thanks Rudi
 
hi Rudi

Maybe there is a space before the sheet name??

You can unprotect your sheet in the code
and protect it again after your code is ready like you do now.

But I like this way.

Protect your worksheets with code like this
Place this in the Thisworkbook module.

The macro's will be working now
It will only protect for the userfaceonly

Private Sub Workbook_Open()
Dim sh As Worksheet
Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Worksheets
sh.Protect "ABCD", , , userinterfaceonly:=True
Next sh
Application.ScreenUpdating = True
End Sub



--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2002 SP-2)




Rudi said:
I was asked to design a worksheet to perform certain calculations. It was however vital that the sheet be protected since it
also includes some macros (VB code) to automate certain processes viz to add rows etc. Rows cannot be added whilst the sheet is
protected.
The operating system, perhaps a little outdated (Windows 95).

Question: Why do I get an error message with the basic code line to protect sheet1 : Worksheets("Sheet1").Protect Password:="ABCD"
The minute I change the code to Sheet2, the processs it completed immediately! Please help.
Incidently, the above code runs beautifully on later versions, viz 98, 2000 etc. Please help. I have tried several code
methods, none which seem to work!
 

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