Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Strange error when changing locked status of cells

Hi
Trying to answer a post for someone else and have come down to this.
I have a sheet called InputDetails. I save the file which calls the
sub rspProtectInputSheet from the BeforeSave event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call rspProtectInputSheet
End Sub

Public Sub rspProtectInputSheet()
Dim password As String 'This line of code is optional
password = "xxxx"
Worksheets("InputDetails").Cells.Locked = True
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub

I now have InputDetails password protected. I can save the file again
without a problem. I can unprotect the sheet, edit it and save and
again the sheet is protected.
Now I close the file and reopen it. When I save I now get an error
"Unable to Set the Locked Property of the Range class" with the line

Worksheets("InputDetails").Cells.Locked = True

highlighted.
Any ideas why this happens??

regards
Paul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default Strange error when changing locked status of cells

You are attempting to lock something that is already locked, just throw a
check in for it.

Public Sub rspProtectInputSheet()
Dim password As String 'This line of code is optional
password = "xxxx"
If Worksheets("InputDetails").Cells.Locked = False Then
Worksheets("InputDetails").Cells.Locked = True
End If
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


" wrote:

Hi
Trying to answer a post for someone else and have come down to this.
I have a sheet called InputDetails. I save the file which calls the
sub rspProtectInputSheet from the BeforeSave event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call rspProtectInputSheet
End Sub

Public Sub rspProtectInputSheet()
Dim password As String 'This line of code is optional
password = "xxxx"
Worksheets("InputDetails").Cells.Locked = True
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub

I now have InputDetails password protected. I can save the file again
without a problem. I can unprotect the sheet, edit it and save and
again the sheet is protected.
Now I close the file and reopen it. When I save I now get an error
"Unable to Set the Locked Property of the Range class" with the line

Worksheets("InputDetails").Cells.Locked = True

highlighted.
Any ideas why this happens??

regards
Paul


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Strange error when changing locked status of cells

Hi Paul

Your worksheet is protected, so you can't change the behaviour of the cells.

Regards,
Per

skrev i meddelelsen
...
Hi
Trying to answer a post for someone else and have come down to this.
I have a sheet called InputDetails. I save the file which calls the
sub rspProtectInputSheet from the BeforeSave event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call rspProtectInputSheet
End Sub

Public Sub rspProtectInputSheet()
Dim password As String 'This line of code is optional
password = "xxxx"
Worksheets("InputDetails").Cells.Locked = True
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub

I now have InputDetails password protected. I can save the file again
without a problem. I can unprotect the sheet, edit it and save and
again the sheet is protected.
Now I close the file and reopen it. When I save I now get an error
"Unable to Set the Locked Property of the Range class" with the line

Worksheets("InputDetails").Cells.Locked = True

highlighted.
Any ideas why this happens??

regards
Paul


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Strange error when changing locked status of cells

Thanks, I'll do that.
But why can I repeatedly save the file, where the cells are locked and
the sheet protected after the first save? The error only crops up when
I close it, reopen and then save.
Not a practical problem as you say, but odd. I'm using Excel 2003 with
XP Professional.
regards
Paul

On Jul 3, 4:43*pm, John Bundy (remove) wrote:
You are attempting to lock something that is already locked, just throw a
check in for it.

Public Sub rspProtectInputSheet()
Dim password As String * 'This line of code is optional
password = "xxxx"
If Worksheets("InputDetails").Cells.Locked = False Then
Worksheets("InputDetails").Cells.Locked = True
End If
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub
--
-John
Please rate when your question is answered to help us and others know what
is helpful.



" wrote:
Hi
Trying to answer a post for someone else and have come down to this.
I have a sheet called InputDetails. I save the file which calls the
sub rspProtectInputSheet from the BeforeSave event.


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call rspProtectInputSheet
End Sub


Public Sub rspProtectInputSheet()
Dim password As String * 'This line of code is optional
password = "xxxx"
Worksheets("InputDetails").Cells.Locked = True
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub


I now have InputDetails password protected. I can save the file again
without a problem. I can unprotect the sheet, edit it and save and
again the sheet is protected.
Now I close the file and reopen it. When I save I now get an error
"Unable to Set the Locked Property of the Range class" with the line


Worksheets("InputDetails").Cells.Locked = True


highlighted.
Any ideas why this happens??


regards
Paul- Hide quoted text -


- Show quoted text -


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 772
Default Strange error when changing locked status of cells

lol that makes sense! Overthought it myself.
--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"Per Jessen" wrote:

Hi Paul

Your worksheet is protected, so you can't change the behaviour of the cells.

Regards,
Per

skrev i meddelelsen
...
Hi
Trying to answer a post for someone else and have come down to this.
I have a sheet called InputDetails. I save the file which calls the
sub rspProtectInputSheet from the BeforeSave event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Call rspProtectInputSheet
End Sub

Public Sub rspProtectInputSheet()
Dim password As String 'This line of code is optional
password = "xxxx"
Worksheets("InputDetails").Cells.Locked = True
Worksheets("InputDetails").Protect password, contents:=True, _
Userinterfaceonly:=True, AllowFormattingColumns:=False
End Sub

I now have InputDetails password protected. I can save the file again
without a problem. I can unprotect the sheet, edit it and save and
again the sheet is protected.
Now I close the file and reopen it. When I save I now get an error
"Unable to Set the Locked Property of the Range class" with the line

Worksheets("InputDetails").Cells.Locked = True

highlighted.
Any ideas why this happens??

regards
Paul



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 formulas in locked cells from changing if data is moved Cleve Excel Discussion (Misc queries) 3 July 24th 08 03:12 PM
Having trouble changing the Locked status Brad E. Excel Programming 5 June 24th 08 03:59 PM
.xls is locked for editing. Really strange. Sander16v Excel Discussion (Misc queries) 2 July 13th 06 12:40 PM
Copy Locked Cell Status Sige Excel Programming 6 September 23rd 05 03:52 PM
Changing the locked propery of merged cells. The Wonder Thing[_3_] Excel Programming 1 October 26th 04 09:08 PM


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