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
我有此代码用于从 SharePoint 网络打开和编辑工作簿。现在,当其他人正在编辑/打开文件时,我运行此代码,就会弹出警报。
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
如果 Workbooks.open 不成功,我想禁用任何弹出窗口/警报并转到 Errhandler。