簡體   English   中英

如何檢查當前用戶是否已從共享工作簿中刪除?

[英]How to check whether the current user has been removed from the shared workbook?

我有一個共享文檔,該文檔在關閉時會運行各種命令。 這包括正常保存(如果仍在共享文檔)和另存為共享(如果未共享文檔)。

當有人將文檔打開一段時間然后關閉時,就會出現問題。 該文檔會自動覆蓋當前文檔(如果使文檔成為非共享文檔,或者它在運行.save命令時提供了覆蓋選項),並且同時輸入的數據可能會丟失。

如何檢查是否從文檔中刪除了用戶,以便在這種情況下可以跳過保存部分?

Private Sub Workbook_BeforeClose(Cancel As Boolean)

    For i = 1 To Sheets.Count     
        If Sheets(i).ProtectContents = False Then
            Call Protect_Sheets 'Protects all the sheets
        End If
    Next i

    If ActiveWorkbook.ProtectStructure = False Then
        Call Protect_Workbook 'Protects the workbook
    End If

    If ActiveWorkbook.MultiUserEditing = False Then
        Call SaveAsShared 'Saves the workbook as shared (overrides)
    Else
        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))
    End If

End Sub

如果可能的話,我想要另一個“ If”(在調用SaveAsShared函數之前),當從工作簿中刪除用戶時,它將終止Sub。 任何幫助都感激不盡! 提前致謝!

我遇到了一個臨時修復程序。 我使用了一個命令(ShowConflictHistory),當您將其踢出文檔后,該命令將返回錯誤,然后使用錯誤處理技術來保存唯一的副本。

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

如果有人提出了更常規的解決方案。 請告訴我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM