Unshare and Reshare a workbook
I have the following to unshare and reshare a workbook. It also adds
and removes worksheet protection based on which command button is pushed (using two control toolbox - command buttons on worksheet). The code works the first time I click on one of the buttons but fails on subsequent clicks. Below is the code. Advice on how to fix this problem would be appreciated. Thanks. Matt Private Sub CommandButton1_Click() If ThisWorkbook.MultiUserEditing Then ThisWorkbook.UnprotectSharing ThisWorkbook.ExclusiveAccess End If For Each sh In ThisWorkbook.Worksheets sh.Unprotect Next If Not ThisWorkbook.MultiUserEditing Then ThisWorkbook.SaveAs Filename:=ThisWorkbook.FullName, _ accessMode:=xlShared End If End Sub Private Sub CommandButton2_Click() If ThisWorkbook.MultiUserEditing Then ThisWorkbook.UnprotectSharing ThisWorkbook.ExclusiveAccess End If For Each sh In ThisWorkbook.Worksheets sh.Protect Next If Not ThisWorkbook.MultiUserEditing Then ThisWorkbook.SaveAs Filename:=ThisWorkbook.FullName, _ accessMode:=xlShared End If End Sub |
All times are GMT +1. The time now is 08:49 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com