View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default VBA to Protect Worksheet

You may have been saved a little trouble by telling excel that you want to only
use variables that you declare.

If you had:
Option Explicit

At the top of your module, then every variable would have to have a:
dim xxxx as yyyyy
statement.

And Password may have been flagged as an undeclared variable.

It may seem like extra work to have to declare all your variables, but it can
stop the kind of error you had and even these hard to see ones:

Row1 = Rowl + 1

(one is row-one and one is row-ell)

And you get all the nice intellisense on top of this.

dim wks as worksheet
type
wks.
As soon as you hit that dot (.), you'll get a list off all the things that can
come next.



Alex wrote:

YES!!!! Thanks so much Dave - I've trying everything.

"Dave Peterson" wrote:

Try FALSE (all caps).

If that doesn't work, you could break the password...
(Visit JE McGimpsey's site: http://mcgimpsey.com/excel/removepwords.html)

Alex wrote:

I accidentally used the following code in some VBA to protect my worksheet:
ActiveSheet.Protect Password = "grencr" (I excluded the colon)

I should have used: ActiveSheet.Unprotect Password:="grencr".

The code worked and my worksheet is now protected, but I'm not sure what the
password is. It is no longer grencr. Any idea what my password was set to
since I didn't include the : in the code?

Thanks


--

Dave Peterson


--

Dave Peterson