ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with unprotecting worksheet in Excel 97 (https://www.excelbanter.com/excel-programming/281353-help-unprotecting-worksheet-excel-97-a.html)

Steve Mikula

Help with unprotecting worksheet in Excel 97
 
I am trying to unprotect a worksheet in some VB code I am
writing in Excel 97. The code works correctly in Excel
2000, however I get the following error in Excel 97:

Run-time error '1004'
Unprotect method of Worksheet class failed

Here is the code, I am getting the error on the 2nd line:

If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect
If CheckBox6.Value = True Then
....

Can anyone help I have been trying to figure this out for
weeks?

Ken Macksey

Help with unprotecting worksheet in Excel 97
 
Hi

If you are using a command button to run the code, Be sure to
set the Takefocusonclick property of the command button to false.
If that does not work, select a cell on the worksheet first like the code
below.

If ActiveSheet.ProtectContents = True Then
Cells(1, "a").Select
ActiveSheet.Unprotect
End If


It works for me.

HTH

Ken


"Steve Mikula" wrote in message
...
I am trying to unprotect a worksheet in some VB code I am
writing in Excel 97. The code works correctly in Excel
2000, however I get the following error in Excel 97:

Run-time error '1004'
Unprotect method of Worksheet class failed

Here is the code, I am getting the error on the 2nd line:

If ActiveSheet.ProtectContents = True Then
ActiveSheet.Unprotect
If CheckBox6.Value = True Then
....

Can anyone help I have been trying to figure this out for
weeks?




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.530 / Virus Database: 325 - Release Date: 22/10/2003




All times are GMT +1. The time now is 02:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com