Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unprotecting a worksheet

Status
Not open for further replies.

mchugh

Programmer
Jun 16, 2003
17
GB
hi

i'm currently working on a simple module for a spreadsheet that my father uses at work. the problem i am having is related to protection. certain columns have to be protected, so that people that use the spread sheet cant just input any old values. setting this up is fine. the problem is, that i need to edit the value of the cells in VBA. now i have tried to unrpotect the sheet in code, but it simply wont work. i'm trying to do something like this:

WorkSheets("Price Match").Activate
ActiveSheet.Unprotect("password")

i've tried this lots of different ways round, but everyway i've tried it, i get a run time error - 1004 "unprotect method failed" or something similar

does anyone have any ideas? only its driving me crazy!

thanks in advance
Craig
 
hmmm, ok, its stopped working again, but i didnt change anything :s something very odd is going on...
 
You don't need to activate OR select to protect / unprotect the sheet y'know

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
 
*cries* i cant get this to work at all. when i thought it was working, i think i must have manually unprotected it, and then ran the code - so if theres no protection on the sheet, it runs ok, and it re-protects when its finished successfully too. it just doesnt seem to want to unprotect it at all - always the same error.
 
This is going to be a long shot, but:

I had a VERY odd and unsolveable error a while back that turned out to be completely unrelated to the error message I was getting. Rob Broekhuis spotted the fact that I was using "End" instead of "Exit Sub" in a different module. Fixing that cleared up my error!

Whether or not that is your exact problem, the moral of the story is that Excel can be ridiculously sensitive to seemingly small abuses of the code. I suggest you review your code - especially modules that call or are called by another sub.

Try disabling all subs in the workbook, and running one that does nothing but unlock the sheet. If that works, start adding the other subs back in one at a time.

Hey, nobody ever said debugging was always easy!

Hope this helps somehow.

VBAjedi [swords]
 
Have you tired making a copy of the "price match" sheet and running your macro against the copy?

Glenn
 
i think i'll start a blank work book, and build it again from the bottom up - theres hardly any code anyway, so it wont take that long.
 
hmmm, i dont suppose anyone could send me a small spreadsheet (doesnt need any data) where it unprotects a password protected sheet in code, and then reprotects it?

it would be most appreciated!

its just i just removed ALL code from the project, except those key lines, and that still broke :s
 
post your email and I'll send you something

Rgds
Geoff
Si hoc legere scis, nimis eruditionis habes
 
hi

the problem seems to have been resolved by changing machines - i.e. the installation on the computer i was using seems to be dodgy :\ how frustrating.

thanks for all your help
Craig

(cheers for the .xls geoff)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top