Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do you Determine if a Worksheet is protected?

I have one sub routines that is called from several locations in my VBA code;
sometimes the worksheet is already unprotected when the sub routine is called
and sometimes it is not. The problem is that my sub routine makes changes
to the sheet and reprotects. When this is called on by code that already
unprotected, then the sheet is protected after the routine is called and the
next line that edits the sheet crashes. I cannot remove the protect
statement from the sub routine, because it would occasionally cause the sheet
to remian unprotected. Is there a way for the sub routine to check to see if
the worksheet is protected so I can add an if statement to check this. if
the worksheet is protected when the sub routine is called, then it will
unprotect, make changes, and re-protect; if it is not protected, then it will
leave the sheet unprotected.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How do you Determine if a Worksheet is protected?

You can test it like this

If ActiveSheet.ProtectContents = True Then



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"nesmith6866" wrote in message ...
I have one sub routines that is called from several locations in my VBA code;
sometimes the worksheet is already unprotected when the sub routine is called
and sometimes it is not. The problem is that my sub routine makes changes
to the sheet and reprotects. When this is called on by code that already
unprotected, then the sheet is protected after the routine is called and the
next line that edits the sheet crashes. I cannot remove the protect
statement from the sub routine, because it would occasionally cause the sheet
to remian unprotected. Is there a way for the sub routine to check to see if
the worksheet is protected so I can add an if statement to check this. if
the worksheet is protected when the sub routine is called, then it will
unprotect, make changes, and re-protect; if it is not protected, then it will
leave the sheet unprotected.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How do you Determine if a Worksheet is protected?

Hi,

Something like this

For X = 1 To Worksheets.Count
If Sheets(X).ProtectContents = True Then
MsgBox "SheetProtected"
Else
MsgBox "SheetNotProtected"
End If
Next

Mike

"nesmith6866" wrote:

I have one sub routines that is called from several locations in my VBA code;
sometimes the worksheet is already unprotected when the sub routine is called
and sometimes it is not. The problem is that my sub routine makes changes
to the sheet and reprotects. When this is called on by code that already
unprotected, then the sheet is protected after the routine is called and the
next line that edits the sheet crashes. I cannot remove the protect
statement from the sub routine, because it would occasionally cause the sheet
to remian unprotected. Is there a way for the sub routine to check to see if
the worksheet is protected so I can add an if statement to check this. if
the worksheet is protected when the sub routine is called, then it will
unprotect, make changes, and re-protect; if it is not protected, then it will
leave the sheet unprotected.

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
How to determine if the workbook is protected? filo666 Excel Programming 0 February 4th 09 07:45 AM
Edit text format in non-protected cells in protected worksheet Bonnie Excel Discussion (Misc queries) 2 April 19th 08 04:48 PM
How to determine whether a protected sheet has a password? Jerry W. Lewis Excel Programming 1 July 28th 07 10:39 PM
Copying a worksheet witrh protected cells to a new worksheet John Excel Worksheet Functions 2 February 1st 06 02:19 PM
Using Worksheet Codename to Determine Worksheet Existence David Copp[_3_] Excel Programming 4 July 2nd 04 08:00 AM


All times are GMT +1. The time now is 07:18 PM.

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

About Us

"It's about Microsoft Excel"