How to open a macro enabled Excel file on a SharePoint in edit mode from an Excel vba?

岁酱吖の 提交于 2021-01-29 15:23:57

问题


I have an macro enabled Excel file on a SharePoint that when a user opens it from the SharePoint the file opens programmatically another macro enabled Excel file on the same SharePoint. The file being opened by the vba macro needs to be edited, and must be editable by multiple users at the same time. However I can't get it to even open in edit mode. Using Office 365

I've tried << ActiveWorkbook.LockServerFile >> but always get an error message << Run-time error 1004: Method 'LockServer' of object'_Workbook' failed >>.

The code that I show below is in the Excel file that is opened manually by the user and that opens automatically the other Excel file. The other Excel file when opened works fine (if I remove the LockServerFile command), all it's macro's work fine, but it is open in read only and changes cannot be saved. Again this file should be editable by multiple users simultaneously.

' this code is in the "ThisWorkbook" tab

Sub workbook_open()

Set DB = Workbooks.Open(DBname, 3, False, , , , True)

ActiveWorkbook.LockServerFile ' this is where is crashes

'more code...

End Sub

' Note: DB is declared in a module

Public DB as Workbook Public Const DBname As String = "https://ledvance365.sharepoint.com ... .xlsm"


回答1:


Looks like << ActiveWorkbook.LockServerFile >> wasn't working because the SharePoint settings was not on "Open Documents in Client Applications by Default"

But once I got the SharePoint owner to change the SharePoint settings to "Open Documents in Client Applications by Default" the << ActiveWorkbook.LockServerFile >> command worked.




回答2:


Maybe check out the following link to check if the file is already locked. https://www.mrexcel.com/forum/excel-questions/906983-vba-support-checking-if-file-locked-sharepoint.html

Also in general it helps if you use your objects when you set them.

Dim DB as Workbook
Set DB = Workbooks.Open(filename:=DBname, editable:=True)
DB.LockServerFile


来源:https://stackoverflow.com/questions/57826669/how-to-open-a-macro-enabled-excel-file-on-a-sharepoint-in-edit-mode-from-an-exce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!