2
我有一個從Sharepoint簽出工作簿並打開工作簿的過程。我注意到,這是產生一個運行時錯誤,如果工作簿中有一些缺少必需的文檔屬性,所以我加了一些錯誤捕獲如下:錯誤處理沒有捕獲運行時錯誤
Public Function getWorkbook(bkPath As String) As Workbook
Dim bk As Workbook
Dim response As Boolean
secAutomation = Application.AutomationSecurity
On Error GoTo errHandler
If Workbooks.CanCheckOut(bkPath) Then
Workbooks.CheckOut bkPath
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Application.EnableEvents = False
Application.DisplayAlerts = False
Set bk = Workbooks.Open(bkPath, False, False)
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.AutomationSecurity = secAutomation
If bk Is Nothing Then
response = dbo_global.setStatus("error", failedToOpen)
End If
Else
response = dbo_global.setStatus("error", checkedout)
Set bk = Nothing
End If
Set getWorkbook = bk
Exit Function
errHandler:
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.AutomationSecurity = secAutomation
If Not bk Is Nothing Then
bk.Close False
Set bk = Nothing
End If
response = dbo_global.setStatus("error", checkoutProblem)
End Function
dbo_global.setStatus()
用於插入條目到Access錯誤日誌的功能。
錯誤被提出在Workbooks.CheckOut bkPath
,但不是去errHandler
塊,我得到一個錯誤消息框:
Run-time error '-2147467259 (80004005)':
This document cannot be checked in.
我想通過一旦打開關閉工作簿進行處理錯誤,並丟棄結帳,但我不知道如何捕捉errHandler
代碼中的錯誤。
編輯:如果有幫助,這是警告消息,我在工作簿的頂部得到:
Required Properties
To save to the server, correct the invalid or missing required properties.