code error if file is shared

kashyap

Board Regular
Joined
Mar 28, 2009
Messages
173
Hi, I have the below code but when I share workbook it does't work.. any help pls

Sub UnP()
Dim wks As Worksheet
Dim strPassword

strPassword = InputBox("Enter the password", "Password")

ActiveSheet.Unprotect Password:=strPassword
Range("A4:I1000").Select
Selection.Locked = False
ActiveSheet.Protect contents:=False
ActiveSheet.Protect Password:=ActiveSheet.Range("P1").Value
Application.Goto Reference:="R4C1"
Selection.End(xlDown).Select

On Error GoTo 0

End Sub
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,813
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
You cannot protect or unprotect sheets in a shared workbook. Additionally, Shared Workbooks are notoriously unreliable and I'd recommend you avoid them if at all possible.
 

kashyap

Board Regular
Joined
Mar 28, 2009
Messages
173
But unfortunately, it should be shared.. ist't there a way out of this..?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,813
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
Not without unsharing the workbook, changing the protections and reprotecting it.
 

kashyap

Board Regular
Joined
Mar 28, 2009
Messages
173

ADVERTISEMENT

Atleat is it possible to lock and unlock cells?
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
35,813
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
That requires protecting and unprotecting the sheets, which you can't do.
 

kashyap

Board Regular
Joined
Mar 28, 2009
Messages
173
Oh..! is there any other ways to make a sheet read only in shared file?

What is the use of [FONT=Verdana, Arial, Helvetica]ActiveWorkbook.UnprotectSharing[/FONT]
 

Watch MrExcel Video

Forum statistics

Threads
1,118,572
Messages
5,572,990
Members
412,493
Latest member
faram
Top