ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Xl2007 not unprotecting worksheet!!!! (https://www.excelbanter.com/excel-programming/430960-xl2007-not-unprotecting-worksheet.html)

Mike[_127_]

Xl2007 not unprotecting worksheet!!!!
 
Hi,

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
.Delete
....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

Xl2007 not unprotecting worksheet!!!!
 
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


"Mike" wrote in message
...
Hi,

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
.Delete
...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?




All times are GMT +1. The time now is 07:58 AM.

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