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?
<code>Private Sub Workbook_BeforeClose(Cancel As Boolean) </code>
<code>For i = 1 To Sheets.Count </code>
<code></code><code> If Sheets(i).ProtectContents = False Then</code><code> </code>
<code>Call Protect_Sheets 'Protects all the sheets</code><code> </code>
<code>End If</code><code> </code>
<code>Next i</code><code></code><code> </code>
<code></code>
<code>If ActiveWorkbook.ProtectStructure = False Then</code><code> </code>
<code>Call Protect_Workbook 'Protects the workbook</code><code> </code>
<code>End If</code><code></code><code> </code>
<code></code>
<code>If ActiveWorkbook.MultiUserEditing = False Then</code><code> </code>
<code>Call SaveAsShared 'Saves the workbook as shared (overrides)</code><code> </code>
<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>
<code>End If</code>
<code></code><code></code><code></code>
<code>End Sub</code>
<code></code><code></code>
<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
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?
<code>Private Sub Workbook_BeforeClose(Cancel As Boolean) </code>
<code>For i = 1 To Sheets.Count </code>
<code></code><code> If Sheets(i).ProtectContents = False Then</code><code> </code>
<code>Call Protect_Sheets 'Protects all the sheets</code><code> </code>
<code>End If</code><code> </code>
<code>Next i</code><code></code><code> </code>
<code></code>
<code>If ActiveWorkbook.ProtectStructure = False Then</code><code> </code>
<code>Call Protect_Workbook 'Protects the workbook</code><code> </code>
<code>End If</code><code></code><code> </code>
<code></code>
<code>If ActiveWorkbook.MultiUserEditing = False Then</code><code> </code>
<code>Call SaveAsShared 'Saves the workbook as shared (overrides)</code><code> </code>
<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>
<code>End If</code>
<code></code><code></code><code></code>
<code>End Sub</code>
<code></code><code></code>
<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