Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Protect sheets

Greetings and TIA for your time
I am using the code below to protect selected worksheets so that the user
can only select unlocked cells and can enter comments (in unlocked cells)

Running the code below has the desired effect. However, when I save the
file, close and re-open, the protection is still in place but the user can
now also select locked cells. How do I prevent the user selecting locked
cells after save, close and re-open?

Sub ProtectSelectedSheets()
Dim wks As Worksheet
Dim myarray()
ReDim myarray(1 To ActiveWindow.SelectedSheets.Count)
counter = 0
For Each wks In ActiveWindow.SelectedSheets
counter = counter + 1
myarray(counter) = wks.Name
Next
For i = 1 To counter
With Worksheets(myarray(i))
.EnableSelection = xlUnlockedCells
.Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True
End With
Next
End Sub
--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Protect sheets


Dear Sir

Try This:

Invert the order of the following two statements:

.EnableSelection = xlUnlockedCells
.Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True

I guess ".enableproctection =xlunlockedCells" should go last... Afte
the protect statement.

Hope this helps.

Regards

Juan Carlo

--
cscor
-----------------------------------------------------------------------
cscorp's Profile: http://www.excelforum.com/member.php...fo&userid=2401
View this thread: http://www.excelforum.com/showthread.php?threadid=37699

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Protect sheets


I have a code that fills out many cells in the rows. and I have a
picture named: *PIC1* placed in sheet 2. I want the picture to popup
once I run the macro. But I also want the picture to be scrolled down
in the middle as the rows are filled (i.e as the macro is running).

What is the code that I shiuld use?
Thank you so much.

All the best,
Nawaf
@ 7572


--
countryfan_nt
------------------------------------------------------------------------
countryfan_nt's Profile: http://www.excelforum.com/member.php...o&userid=11051
View this thread: http://www.excelforum.com/showthread...hreadid=376998

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Protect sheets

Unfortunately, changing the order won't help in this situation. The
enableSelection property is non-persistent and must be set each time the
workbook is opened. You can do this in the workbook_open event

See Chip Pearson's page on events if you are not familiar with them:

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"cscorp" wrote in
message ...

Dear Sir

Try This:

Invert the order of the following two statements:

EnableSelection = xlUnlockedCells
Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True

I guess ".enableproctection =xlunlockedCells" should go last... After
the protect statement.

Hope this helps.

Regards

Juan Carlos


--
cscorp
------------------------------------------------------------------------
cscorp's Profile:

http://www.excelforum.com/member.php...o&userid=24015
View this thread: http://www.excelforum.com/showthread...hreadid=376998



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Protect sheets

Thanks Tom,
.... so. if i understand it right, when setting with code, enableSelection
needs to be reset every time the workbook is opened. Unlike when setting
'manually' on the sheet when it is set 'forever'? ie: code cannot directly
mimic the manual setting?
TIA
--
David


"Tom Ogilvy" wrote:

Unfortunately, changing the order won't help in this situation. The
enableSelection property is non-persistent and must be set each time the
workbook is opened. You can do this in the workbook_open event

See Chip Pearson's page on events if you are not familiar with them:

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"cscorp" wrote in
message ...

Dear Sir

Try This:

Invert the order of the following two statements:

EnableSelection = xlUnlockedCells
Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True

I guess ".enableproctection =xlunlockedCells" should go last... After
the protect statement.

Hope this helps.

Regards

Juan Carlos


--
cscorp
------------------------------------------------------------------------
cscorp's Profile:

http://www.excelforum.com/member.php...o&userid=24015
View this thread: http://www.excelforum.com/showthread...hreadid=376998






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Protect sheets

In xl2000 and earlier, it is non-persistent for both manual or code
settings. In xl2002, they changed the dialog for setting protection - but
as I recall, this is not supported programmatically and the old property is
used programmatically. So I believe this is the case - that is is not
persistent programmatically, but in xl2002 and later, is persistent if set
manually.

You note that in the revised protect method for xl2002/3

expression.Protect(Password, DrawingObjects, Contents, Scenarios,
UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns,
AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows,
AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows,
AllowSorting, AllowFiltering, AllowUsingPivotTables)

there is no provision for setting enableselection. An apparent
oversight/bug.

--
Regards,
Tom Ogilvy



"David" wrote in message
...
Thanks Tom,
... so. if i understand it right, when setting with code, enableSelection
needs to be reset every time the workbook is opened. Unlike when setting
'manually' on the sheet when it is set 'forever'? ie: code cannot directly
mimic the manual setting?
TIA
--
David


"Tom Ogilvy" wrote:

Unfortunately, changing the order won't help in this situation. The
enableSelection property is non-persistent and must be set each time the
workbook is opened. You can do this in the workbook_open event

See Chip Pearson's page on events if you are not familiar with them:

http://www.cpearson.com/excel/events.htm

--
Regards,
Tom Ogilvy

"cscorp" wrote in
message ...

Dear Sir

Try This:

Invert the order of the following two statements:

EnableSelection = xlUnlockedCells
Protect Password:="pwd", DrawingObjects:=False, _
Contents:=True, Scenarios:=True, userinterfaceonly:=True

I guess ".enableproctection =xlunlockedCells" should go last... After
the protect statement.

Hope this helps.

Regards

Juan Carlos


--
cscorp


------------------------------------------------------------------------
cscorp's Profile:

http://www.excelforum.com/member.php...o&userid=24015
View this thread:

http://www.excelforum.com/showthread...hreadid=376998






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Protect sheets

Thanks again Tom,
It's a privilege to communicate with you.
--
David

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
Protect sheets in one go mohavv Excel Discussion (Misc queries) 4 March 11th 08 10:21 PM
Protect some sheets in an xls but not all. lucky1 Excel Worksheet Functions 0 June 6th 07 09:05 PM
Protect all Sheets Phil Osman Excel Discussion (Misc queries) 0 June 17th 05 01:55 AM
how to protect sheets from VBA? jon Excel Programming 1 September 16th 04 06:11 PM
Protect a few sheets Soniya Excel Programming 0 August 27th 03 08:11 AM


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

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"