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.
Errhandler
, anddebug.print
the value oferr.number
, then try again. What is the value orerr.number
when you fall into theErrhandler
?