Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default 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
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
Can't unshare workbook Mr. m0le[_2_] Excel Worksheet Functions 7 July 9th 09 01:56 AM
how to unshare a workbook? Todd Excel Worksheet Functions 3 April 9th 08 10:09 PM
Unshare a Shared Workbook Dave Excel Discussion (Misc queries) 1 February 1st 08 08:11 PM
Can't UNshare a shared workbook Phrank Excel Discussion (Misc queries) 1 January 27th 07 02:59 PM
unshare workbook mlh Setting up and Configuration of Excel 1 September 28th 06 02:29 PM


All times are GMT +1. The time now is 07:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"