Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default which is right, protect password:="xyz" or protect password = "xyz

This is the proper way to protect a worksheet in code.

Public Sub Protect()
ActiveSheet.Protect Password:="xyz"
End Sub

I use 2007 and ActiveSheet.Protect Password = "xyz" throws an error. I use
to use 2003 and I'm sure it would throw an error as well. The .Protect
method has lots of parameters. Password is one of those parameters and the
correct syntax to set parameters in VB is to spell the parameter with :=
after it, like Password:=. Hope this helps! If so, let me know, click "YES"
below.
--
Cheers,
Ryan


"HGood" wrote:

Hi,

I'm perplexed. Up until about a week ago I've had no problem with my code
unprotecting and protecting the worksheets in this spreadsheet. I'm using
Excel 2007.

But a few days ago I couldn't manually unprotect the worksheet anymore. I
had to do it with vba code, even tho it used the same password.

I've found that if I use this code to protect it I cannot unprotect it
manually.
Public Sub Protect()
ActiveSheet.Protect Password = "xyz"
End Sub

But if I use this code to protect it I can unprotect it manually.
Public Sub Protect()
ActiveSheet.Protect Password:="xyz"
End Sub

It may be difficult to see, but difference between the first code and the
second is that in the second there is a colon after the word Password. In the
top one there is a space instead of a colon.

What is going on with this?
Why would the colon make a difference?
Why would Excel accept it both ways, yet act differently?

To make matters worse, I can't get to code to work consistently in the
numerous places where I have it unprotect and protect a worksheet
consistently using either the colon or space method. Seems I'm going
backwards.

Can anyone help with this?

Thank you,
Harold

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
Unable to password-protect "VeryHidden" worksheet exalan New Users to Excel 4 May 9th 09 08:13 AM
OT I would want protect my sheets of excel from a "password recovery" software... How? -= Luca =- Excel Worksheet Functions 3 May 31st 06 10:11 AM
I would want protect my sheets of excel from a "password recovery" software... How? -= Luca =- Excel Programming 5 May 31st 06 02:00 AM
ActiveWorkbook.Protect password:=range("rangename") does not work WimR Excel Programming 2 June 26th 05 08:47 AM
no password carryover with "protect sheet" in macro Trevor Shuttleworth Excel Programming 0 February 12th 04 09:44 PM


All times are GMT +1. The time now is 02:21 PM.

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

About Us

"It's about Microsoft Excel"