Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Cursor and Sheet Protection may09


Hi All,
I use the procs below to protect and unprotect sheets.

At times, (and I can't find the 'pattern'), I lose the
cursor after protecting the sheet.

After 'manual' protection the cursor moves to a unlocked cell.

If I've changed a locked cell in a macro, do I have to select a
Not .Locked cell to make sure the cursor is there
after protection ?

Thanks.



Sub UNprotectStdId(Ws As Worksheet, Optional Id As String = "")
If Not Ws Is Nothing Then Ws.UNprotect Id
End Sub

' Code to change a range

Sub ProtectStdId(Ws As Worksheet, Optional Id As String = "", _
Optional SelectionType As Long = xlUnlockedCells)

If Not Ws Is Nothing Then
Ws.Protect Id, AllowFormattingCells:=True
Ws.EnableSelection = SelectionType
End If
End Sub
--
Neal Z

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Cursor and Sheet Protection may09

You can find unlocked cells like this

Dim r as Excel.Range

for each r in WS.UsedRange
if not r.locked then
'Unlocked
else
'Locked
end if
next r


"Neal Zimm" wrote:


Hi All,
I use the procs below to protect and unprotect sheets.

At times, (and I can't find the 'pattern'), I lose the
cursor after protecting the sheet.

After 'manual' protection the cursor moves to a unlocked cell.

If I've changed a locked cell in a macro, do I have to select a
Not .Locked cell to make sure the cursor is there
after protection ?

Thanks.



Sub UNprotectStdId(Ws As Worksheet, Optional Id As String = "")
If Not Ws Is Nothing Then Ws.UNprotect Id
End Sub

' Code to change a range

Sub ProtectStdId(Ws As Worksheet, Optional Id As String = "", _
Optional SelectionType As Long = xlUnlockedCells)

If Not Ws Is Nothing Then
Ws.Protect Id, AllowFormattingCells:=True
Ws.EnableSelection = SelectionType
End If
End Sub
--
Neal Z

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 345
Default Cursor and Sheet Protection may09

Wow Barb, that was fast ....

I guess I was not clear in my question, I know about the .locked property
and how to find cells that are/not locked.

To restate, when I manually protect a sheet, the cursor always moves to a
not locked cell if there is one.

In my VBA code however, there are times when I unprotect a sheet to make
changes to locked cells, then, after protecting the sheet, when I go back to
look at it, there is NO cursor to be found. When I unprotect the sheet
and then re-protect it, the cursor magically comes back to life.

How do I stop this from happening ? I am hoping that your answer meant
that I do indeed have to find a unlocked cell before protecting the sheet.

But if that's true, that why does that never happen manually ?

Thanks,
Neal



--
Neal Z


"Barb Reinhardt" wrote:

You can find unlocked cells like this

Dim r as Excel.Range

for each r in WS.UsedRange
if not r.locked then
'Unlocked
else
'Locked
end if
next r


"Neal Zimm" wrote:


Hi All,
I use the procs below to protect and unprotect sheets.

At times, (and I can't find the 'pattern'), I lose the
cursor after protecting the sheet.

After 'manual' protection the cursor moves to a unlocked cell.

If I've changed a locked cell in a macro, do I have to select a
Not .Locked cell to make sure the cursor is there
after protection ?

Thanks.



Sub UNprotectStdId(Ws As Worksheet, Optional Id As String = "")
If Not Ws Is Nothing Then Ws.UNprotect Id
End Sub

' Code to change a range

Sub ProtectStdId(Ws As Worksheet, Optional Id As String = "", _
Optional SelectionType As Long = xlUnlockedCells)

If Not Ws Is Nothing Then
Ws.Protect Id, AllowFormattingCells:=True
Ws.EnableSelection = SelectionType
End If
End Sub
--
Neal Z

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
Excel Data Protection Best Practice: AKA: Real Sheet Protection Mushman(Woof!)[_2_] Excel Discussion (Misc queries) 4 December 30th 09 01:20 AM
Excel Data Protection- AKA: Sheet/Macro Password Protection Mushman(Woof!) Setting up and Configuration of Excel 0 December 29th 09 06:50 AM
move cursor on one sheet moves cursor on all sheets tdworden Excel Discussion (Misc queries) 2 July 22nd 07 10:50 PM
Putting Cursor in Cell A1 of each Worksheet, then ending cursor on smalest sheet name according to VBA Editor Matt[_40_] Excel Programming 1 May 14th 07 09:21 AM
Sheet protection error msg - Unrequested sheet activation deltree[_3_] Excel Programming 0 January 28th 04 06:20 PM


All times are GMT +1. The time now is 09:12 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"