如何检查当前用户是否从共享工作簿中删除? [英] How to check whether the current user has been removed from the shared workbook?

查看:138
本文介绍了如何检查当前用户是否从共享工作簿中删除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共享文档,在关闭时运行各种命令。这包括正常保存(如果文档仍然共享)并保存为共享(如果文档未共享)。



当一个人离开文档一段时间,然后关闭它时,会出现问题。该文档将自动覆盖当前文档(如果文档被取消共享,或者当.save命令运行时,该文档提供了超出的选项),同时输入的数据可能会丢失。



如何检查用户是否从文档中删除,以便保存部分可以跳过,如果是这样的话?

  Private Sub Workbook_BeforeClose(Cancel As Boolean)

对于i = 1 To Sheets.Count
如果Sheets(i).ProtectContents = False然后
调用Protect_Sheets保护所有的工作表
End If
Next i

如果ActiveWorkbook.ProtectStructure = False然后
调用Protect_Workbook'保护工作簿
End If

如果ActiveWorkbook.MultiUserEditing = False然后
调用SaveAsShared将工作簿另存为共享(覆盖)
Else
ActiveWorkbook.Save'只有当文档在关闭时共享时才保存正常(但默认为当前文档名称(在不注意的情况下会覆盖))
End If

End Sub

如果可能,我想要另一个'如果(之前调用SaveAsShared功能),当用户已经从工作簿中删除终止小组。
任何帮助将不胜感激!
提前感谢!



Lou

解决方案

遇到临时修复。我使用一个命令(ShowConflictHistory),当您被踢出文档时,该命令返回一个错误,然后使用错误处理技术来保存唯一的副本;

  On Error GoTo Errhandler:
如果ActiveWorkbook.ShowConflictHistory = False或True则返回Err 1004,如果该人已从工作簿中踢出,则可以在ErrHandler中相应处理。
结束如果

继续1:
错误恢复下一步

'''''''''
'主要代码段
'''''''''

退出子

Errhandler:

选择案例错误
案例1004: '如果你被踢出文档,那么会导致错误。
调用SaveCopyOfShared
退出Sub
案例:
GoTo Continue1:
结束选择

End Sub

如果有人想出了一个更传统的解决方案。请让我知道。


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?

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 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

解决方案

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.

这篇关于如何检查当前用户是否从共享工作簿中删除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆