Building custom solutions that extend, automate, and integrate Microsoft 365 apps.
LockServerFile fails
Hi.
At work I get an error when trying to use lockservefile on a sharepoint file, using Windows 10 / Microsoft® Excel® for Microsoft 365 MSO (16.0.14326.20164) 64-bit.
I found out that the same error occurs when using a locally saved file, so then I tried it at home and the same error occurs.
The code used to run on Windows 7, but now that we're on Windows 10 the code errors on the lockserverfile command.
The error is:
Run-time error'1004'
Method ;LockServerFile' of object _Workbook failed
The code I'm using is:
workbooks.open("https://...file path.../test.xlsx")
activeworkbook.lockserverfile
I don't know if this command works on a file on C:, but I've also tried it with the path C:\temp\test.xlsx
I found a couple of other posts on here when posting the question but they don't resolve the issue:
https://learn.microsoft.com/en-us/answers/questions/411187/programaticly-changing-excel-file-from-sharepoint.html - already using the suggestion
https://social.msdn.microsoft.com/Forums/en-US/8665857b-3e51-4c72-95cb-32f7c2a87d29/how-to-open-xlsm-from-sharepoint-url-and-refresh-from-client?forum=sharepointdevelopment - I tried changing the default opening app to no avail
As a workaround, it seems if I wrap the lockserverfile line with On Error Resume Next / On Error Goto 0 the process works, but this seems to be a bit of a dodgy workaround to get the command to work.
Cheers.