Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Can't unshare workbook | Excel Worksheet Functions | |||
how to unshare a workbook? | Excel Worksheet Functions | |||
Unshare a Shared Workbook | Excel Discussion (Misc queries) | |||
Can't UNshare a shared workbook | Excel Discussion (Misc queries) | |||
unshare workbook | Setting up and Configuration of Excel |