Handle "File In Use" dialog box in the code when updatinf files on SharePoint

Viewed 942

I need to edit macro enabled Excel workbooks in SharePoint from Excel files stored locally.

Many users can try to update a SharePoint file at the same time. A yellow belt pops-up with information: READ ONLY We opened this workbook read-only from the server (see screen below).

I've a solution to skip that notification:

Private Sub Workbook_Open()
    ActiveWorkbook.LockServerFile  
End Sub

The problem is when one user has .LockServerFile enabled, another notification window shows for other users, notifying that the file is in use (see screen below).

Is it possible to avoid showing this window? Then ActiveWorkbook.LockServerFile will raise an exception, so I could handle it.

Private Sub Workbook_Open()
    'Excel.Application.DisplayAlerts = False 'does not work
    'ActiveWorkbook.ReadOnly = True 'always is read only before .LockServerFile
    ActiveWorkbook.LockServerFile
End Sub

enter image description here

Or maybe there's some other way to update Excel files on Sharepoint, using Excel 2016?

0 Answers
Related