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).
I have come across a temporary fix. I use a command (ShowConflictHistory) which returns an error when you have been kicked out of the document, then I use error handling techniques to save a unique copy;
On Error GoTo Errhandler:
If ActiveWorkbook.ShowConflictHistory = False Or True Then 'This returns Err 1004 if the person has been kicked from the workbook, so it can be handled accordingly in ErrHandler.
End If
Continue1:
On Error Resume Next
'''''''''
'Main code section
'''''''''
Exit Sub
Errhandler:
Select Case Err
Case 1004: 'The error which results if you've been kicked out of the document.
Call SaveCopyOfShared
Exit Sub
Case Else:
GoTo Continue1:
End Select
End Sub
If someone comes up with a more conventional solution. Please let me know.