0
Sub Test()
    Application.ScreenUpdating = False  
    On Error GoTo Errhandler
    Set WB = Workbooks.Open(Database, UpdateLinks:=False, ReadOnly:=False, IgnoreReadOnlyRecommended:=True, Notify:=False, CorruptLoad:=xlNormalLoad)
    On Error GoTo 0
    WB.LockServerFile
    'Edit the workbook.....
    MsgBox ("Program completed! Please check the files")
    Application.ScreenUpdating = True
Exit Sub

Errhandler:
    If err.Number <> 0 Then
        err.Clear
        On Error GoTo 0
        'Error handling.....
        MsgBox ("Error opening workbook! Try again later")
    End If
    Application.ScreenUpdating = True
End Sub

I have this code to open and edit a workbook from SharePoint network. Now, when someone else is editing/have the file opened, and I run this code, there will be a popup alert.

File In Use
This file is locked for editing by XXXXX
Do you want to:
-View a read-only copy
-Save and edit a copy of the file
-Receive a notification when the server file is available

I would like to disable any popup/alert if Workbooks.open is unsuccessful and go to Errhandler.

4
  • Add a breakpoint in your Errhandler, and debug.print the value of err.number, then try again. What is the value or err.number when you fall into the Errhandler? Mar 3, 2021 at 7:52
  • The code does not run into Errhandler. err.Number is 0. The program will continue and make an attempt to run "WB.LockServerFile" which fails with runtime error.
    – mrr010
    Mar 3, 2021 at 7:56
  • It is the "LockServerFile" poping the "File in Use" dialog. How can I disable it? I tried Application.DisplayAlerts=False but no success.
    – mrr010
    Mar 3, 2021 at 8:08
  • I tried to use Open statement to access the file and test for error code but it seems that the statement does not take special characters which my sharepoint file path has.
    – mrr010
    Mar 3, 2021 at 9:40

0

You must log in to answer this question.

Browse other questions tagged .