1

I have a workbook in which i have several sheets according to requirement. In this workbook i have used macros and to lock some particular cells and columns i have used unprotect and protect options. Everything works fine on my machine but when i make it as SharedWorkBook it is giving me errors particularly the ThisWorkBook.Sheets("PSE").Unprotect and ThisWorkBook.Sheets("PSE").Protect statements. So in place of them i used ThisWorkBook.Sheets("PSE").UnprotectSharing and ThisWorkBook.Sheets("PSE").ProtectSharing . Even now also i am getting errors with those lines.


Sub SheetHider()
ThisWorkbook.Sheets("SheetA").UnprotectSharing
Cuser = ThisWorkbook.Sheets("SheetA").Range("A2").Value

and the error is
Runtime error '438' Object doesn't support this property or method.

My Requirement: 1)I have to use Macros, Locking property so that i have to use Unprotect and Protect statements and these things should work when i make it as SharedWorkBook.
I have been searching many sites for this for a week. Atleast give me some alternatives to do this.
Any help will be appreciated greatly. Thanks

2
  • 1
    Could you list the nature of the error/error messages and the line of code where the error occurs?. Some more code won't hurt, too. Otherwise it's difficult to say anything.
    – Jüri Ruut
    Commented Jan 11, 2013 at 6:07
  • @Jüri Ruut Hi, you can see my updated edit. Commented Jan 11, 2013 at 6:40

2 Answers 2

5

UnprotectSharing and ProtectSharing both belong to the Workbook object. So you can't do what you are trying to do.

You can do ThisWorkbook.UnprotectSharing and ThisWorkbook.ProtectSharing but that is only design to protect the Shared Workbook setting so that people can't remove it without a password.

Secondly you can't unprotect or protect sheets when a workbook is shared. You would have to unshare the workbook, unprotect the sheet and then share the workbook again. Which isn't very practicable.

5
  • Oh then it is going to be a very big issue for my project as well as for me. So how can i restrict users to edit and not edit some specific cells or columns dynamically based on Environ("username"). please reply me as soon as possible. Commented Jan 11, 2013 at 7:33
  • Hi Nick,let me state my requirement more clearly. My excel has lots of employee related data. Requirement is that current user should be able to edit only his department data. Also multiple users will be using the sheet simultaneously so they NEED a shared workbook. Everything works fine till I share the workbook. Any thoughts ? Commented Jan 11, 2013 at 9:17
  • @SaiKiranMandhala What you want to do isn't possible with a shared workbook. I'm sorry that my answer isn't what you want to hear, but it is what it is. You will need to either have to use an unshared workbook, or not have protection. Commented Jan 11, 2013 at 9:35
  • thanks for your time. ActiveWorkbook.SaveAs "\\192.148.1.123\Extranet\Hub.xlsm", FileFormat:=52 How can i change the above line to save the file instead of saveAs.Beacause already Hub.xlsm is existing in that path. So i have to save that file instead of saveAs. Commented Jan 11, 2013 at 10:27
  • @SaiKiranMandhala You should open up a new question because it is a different subject, and the information supplied is not enough for me to know what you actually need. It would be great if you could mark the question as answered as well so others will know. Commented Jan 12, 2013 at 13:33
0

You must protect sheets before protecting a shared workbook, unprotecting goes in the reverse order.

1
  • No actually i am unprotecting a sheet and applying unlock to some columns based on userroles after this i am protecting the sheet. And i didn't get your answer, will you please give answer in deatil. Commented Jan 11, 2013 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.