Xl2007 not unprotecting worksheet!!!!




I'm running Win XP and both XL2003 & XL2007. I've got an application
(an .xls file, created in XL2003) with code that unprotects a
worksheet, deletes certain shapes, the reprotects the sheet. However,
in xl 2007, the code doesn't unprotect the sheet!?

here's the code:
shtTarget.unprotect gcstrPassword
While intZ > 1
With shtTarget.Shapes(intZ)
If (.Name Like "pic_*") Then
....more code...

To reiterate,
So this file was created in excel 2003 and runs fine, but my company
is converting to excel 2007 and one of my colleagues, who uses the
file regularly, has switched.

In XL2007, the .delete line gives me an error; so I manually
unprotected the sheet and the code runs fine, so I thought something
in the rest of my code re-protected the sheet. After creating an
error handler (shttarget.unprotect password:=gcstrpassword / resume)
to unprotect the sheet if .delete throws an error, I discovered that
the error handler infinite loops, and that's when I realized the
worksheet.unprotect doesn't actually unprotect!

I have checked with application screenupdating true and false,
enableevents true and false; there is no code that would fire to
'instantly relock' or anything like that. the password constant I'm
using (gcstrpassword) is definitely correct... I'm at a loss...

Anyone have any suggestions?

Patrick Molloy

do a check with just this one line

shtTarget.unprotect gcstrPassword

if it fails - and your comments suggest that it will, record a macro to
unprotect the sheet to see if it differs

as far i can tell though, syntax is correct . but it is case dependent

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