Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How do I unprotect a sheet within a macro?

Please can anyone advise how I can overcome this Run-time error when using
the code
below:

"Unprotect method of worksheet class failed"

Worksheets("Template").Protect Password:="MyPassword"


Or what code should I use to remove a password format a sheet using another
macro and put the same password back on again.
--
Kind Regards

Mick


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 212
Default How do I unprotect a sheet within a macro?

The code used is correct.
(Same format for Protect and Unprotect.)

Are you sure that the password you entered in the code is correct?

Regarding your second query, it is not clear what you mean. Please note
you must "KNOW" the password. You can not get what password is set for
a worksheet, through the code.

Sharad

"Mick" wrote in message
...
Please can anyone advise how I can overcome this Run-time error when using
the code
below:

"Unprotect method of worksheet class failed"

Worksheets("Template").Protect Password:="MyPassword"


Or what code should I use to remove a password format a sheet using
another macro and put the same password back on again.
--
Kind Regards

Mick



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default How do I unprotect a sheet within a macro?

Worksheets("Template").Unprotect Password:="MyPassword"
Worksheets("Template").Protect Password:="MyPassword"

Mike F

"Mick" wrote in message
...
Please can anyone advise how I can overcome this Run-time error when using
the code
below:

"Unprotect method of worksheet class failed"

Worksheets("Template").Protect Password:="MyPassword"


Or what code should I use to remove a password format a sheet using

another
macro and put the same password back on again.
--
Kind Regards

Mick




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How do I unprotect a sheet within a macro?

Mike

I have been able to test this on a new sheet and can get it to work.
However my problem is that I have a template that I am using. If I open the
template and run the macro I get the error message and likewise if I open a
new workbook from it I get the same. But if I step through the macro it
works OK. Does that make sense, it doesn't to me?

Regards

Mick

"Mike Fogleman" wrote in message
news:h46ed.439606$Fg5.140079@attbi_s53...
Worksheets("Template").Unprotect Password:="MyPassword"
Worksheets("Template").Protect Password:="MyPassword"

Mike F

"Mick" wrote in message
...
Please can anyone advise how I can overcome this Run-time error when
using
the code
below:

"Unprotect method of worksheet class failed"

Worksheets("Template").Protect Password:="MyPassword"


Or what code should I use to remove a password format a sheet using

another
macro and put the same password back on again.
--
Kind Regards

Mick






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default How do I unprotect a sheet within a macro?

Are you using xl97?

Are you trying to run your code from a commandbutton from the control toolbox
toolbar placed on a worksheet?

If yes, try changing the .takefocusonclick property to false for that
commandbutton.

If the control you're using doesn't have that property (but it's still from the
control toolbox toolbar), add a line to the top of your procedure.

activecell.activate

There's a bug in xl97 that was fixed in xl2k.

Mick wrote:

Mike

I have been able to test this on a new sheet and can get it to work.
However my problem is that I have a template that I am using. If I open the
template and run the macro I get the error message and likewise if I open a
new workbook from it I get the same. But if I step through the macro it
works OK. Does that make sense, it doesn't to me?

Regards

Mick

"Mike Fogleman" wrote in message
news:h46ed.439606$Fg5.140079@attbi_s53...
Worksheets("Template").Unprotect Password:="MyPassword"
Worksheets("Template").Protect Password:="MyPassword"

Mike F

"Mick" wrote in message
...
Please can anyone advise how I can overcome this Run-time error when
using
the code
below:

"Unprotect method of worksheet class failed"

Worksheets("Template").Protect Password:="MyPassword"


Or what code should I use to remove a password format a sheet using

another
macro and put the same password back on again.
--
Kind Regards

Mick





--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
unprotect sheet macro belvy123 Excel Discussion (Misc queries) 2 March 27th 08 10:36 PM
unprotect sheet macro belvy123 Excel Discussion (Misc queries) 1 March 27th 08 10:32 PM
Macro to Unprotect sheet!? Neo1 Excel Worksheet Functions 5 March 28th 06 05:50 PM
Macro to Unprotect Sheet Eric[_23_] Excel Programming 3 August 4th 04 10:17 PM
Macro to Unprotect Sheet Eric[_23_] Excel Programming 0 August 4th 04 10:11 PM


All times are GMT +1. The time now is 08:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"