Check whether the current user has been removed (kicked) from the shared workbook?

liewelulu

New Member
Joined
Nov 6, 2014
Messages
1
I have a shared document which runs various commands upon close. This includes saving normally (if document is still shared) and saving as shared (if document was unshared).
The problem arises when a person left the document open for a while then close it. The document automatically overrides the current document (if the document was made unshared, or it gives the option to overide when the .save command runs) and the data which was entered meanwhile is potentially lost.
How do I check if the user is removed from the document, so that the saving section can be skipped if that's the case?
[HR][/HR][HR][/HR]

<code>Private Sub Workbook_BeforeClose(Cancel As Boolean) </code>
[HR][/HR]<code>For i = 1 To Sheets.Count </code>[HR][/HR]<code></code><code> If Sheets(i).ProtectContents = False Then</code><code> </code>[HR][/HR]<code>Call Protect_Sheets 'Protects all the sheets</code><code> </code>[HR][/HR]<code>End If</code><code> </code>[HR][/HR]<code>Next i</code><code></code><code> </code>[HR][/HR]<code></code>[HR][/HR]<code>If ActiveWorkbook.ProtectStructure = False Then</code><code> </code>[HR][/HR]<code>Call Protect_Workbook 'Protects the workbook</code><code> </code>[HR][/HR]<code>End If</code><code></code><code> </code>[HR][/HR]<code></code>[HR][/HR]<code>If ActiveWorkbook.MultiUserEditing = False Then</code><code> </code>[HR][/HR]<code>Call SaveAsShared 'Saves the workbook as shared (overrides)</code><code> </code>[HR][/HR]<code>Else</code><code> ActiveWorkbook.Save 'Only saves as normal when the document was shared upon close (but defaults the current document name (which will override when no attention is paid))</code><code> </code>[HR][/HR]<code>End If</code>[HR][/HR]<code></code><code></code><code></code>[HR][/HR]<code>End Sub</code>[HR][/HR]<code></code><code></code>[HR][/HR]<code></code>If possible, I want another 'If' (just before calling the SaveAsShared function), which terminates the Sub when the user has been removed from the workbook. Any help will be much appreciated! Thanks in advance!
Lou

 

Forum statistics

Threads
1,081,773
Messages
5,361,207
Members
400,617
Latest member
barron1

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top