Excel VBA - Problems using Protect/Unprotect a worksheet

G

Gary Richie

Greetings,

I am having problems toggling the Protect mode on a spreadsheet. I ca
Protect/Unprotect from the Tools menu.

The workbook is not protected nor is it shared.

When I execute my macro I get the following error message:
Run-time error '1004':

Unprotect method of Worksheet class failed
The message occurs when I execute either of the following:

- Sheets("SheetName").Unprotect
- Worksheets("SheetName").Unprotect

The macro is executed by clicking on a button on the worksheet.

I am running Excel 97.

Thanks (TIA)
Gar
 
T

Tom Ogilvy

Change the TakeFocusOnClick property of the commandbutton to false. This
should fix it.

Problem fixed in xl2000 and later.
 
H

Hank Scorpio

On Thu, 5 Feb 2004 21:14:54 -0600, Gary Richie

Add the command Activecell.Select before you try the unprotect method.
There's a known issue with command buttons taking the focus in Excel
97 which often causes the kind of problem you're referring to.
 
S

Shafik Inamdar

Greetings,

I am having problems toggling the Protect mode on a spreadsheet. I can
Protect/Unprotect from macro.

When I execute my macro I get the following error message:
Run-time error '1004':

Unprotect method of Worksheet class failed
The message occurs when I execute either of the following:

- Sheets("SheetName").Unprotect
- Worksheets("SheetName").Unprotect

The macro is executed by clicking on a button on the worksheet.

I am running Excel 97.

Thanks
Shafik
 

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