检查SharePoint 365中的工作簿是否被locking以进行编辑

我在SharePoint 365中有一个文档库,并使用本地Excelmacros文件通过VBA联机在SharePoint中打开工作簿。 这适用于类似的代码

location = "https://mycompany.sharepoint.com/sites/ABC/LibraryA/Book1.xlsx" Set wbk = Workbooks.Open(location) 

但是,当用户在Excel Online中编辑工作簿时,工作簿将被locking/正在使用,然后代码会运行提示以保存文件的本地副本。 我想避免这种情况,并分支到代码,如果工作簿正在使用中处理的事情不同。

如果工作簿存储在我的公司文件服务器上,事情会很容易。 我可以使用这个macros代码来检查一个文件是否已经被微软支持网站提供:

 Sub TestFileOpened() ' Test to see if the file is open. If IsFileOpen("c:\Book2.xls") Then ' Display a message stating the file in use. MsgBox "File already in use!" ' ' Add code here to handle case where file is open by another ' user. ' Else ' Display a message stating the file is not in use. MsgBox "File not in use!" ' Open the file in Microsoft Excel. Workbooks.Open "c:\Book2.xls" ' ' Add code here to handle case where file is NOT open by another ' user. ' End If End Sub ' This function checks to see if a file is open or not. If the file is ' already open, it returns True. If the file is not open, it returns ' False. Otherwise, a run-time error occurs because there is ' some other problem accessing the file. Function IsFileOpen(filename As String) Dim filenum As Integer, errnum As Integer On Error Resume Next ' Turn error checking off. filenum = FreeFile() ' Get a free file number. ' Attempt to open the file and lock it. Open filename For Input Lock Read As #filenum Close filenum ' Close the file. errnum = Err ' Save the error number that occurred. On Error GoTo 0 ' Turn error checking back on. ' Check to see which error occurred. Select Case errnum ' No error occurred. ' File is NOT already open by another user. Case 0 IsFileOpen = False ' Error number for "Permission Denied." ' File is already opened by another user. Case 70 IsFileOpen = True ' Another error occurred. Case Else Error errnum End Select End Function 

问题是,当我用SharePoint URL运行这个时,无论文件是否被使用,返回的错误代码是75( path/文件访问错误(错误75)) 。

将SharePoint 365位置映射为networking驱动器(WebDav)不是一个选项。 根据如何configuration和解决在Office 365中连接到SharePoint Online网站的映射networking驱动器中的说明 ,维护的内容太多了。 通过这个对于最终用户来说太多了。

我需要find一种方法来检查与VBA,如果存储在SharePoint联机的文件打开使用,而使用URL来访问该文件。

想法欢迎。

编辑:评论build议方法以只读方式打开工作簿,然后更改工作簿属性或打开工作簿并评估.ReadOnly属性。 这种方法的问题是,如果工作簿从只读更改为编辑,这个对话框popup:

在这里输入图像说明

即使我点击打开只读副本,结果也是错误的。 如果我可以禁止这个对话框,而是评估导致对话框出现的触发器,那么我可以从那里取出它。