我的问题是,如何检查从sharepoint下载的工作簿是否已损坏且是否可以打开。嗯,最简单的方法是尝试打开它。我已经写了一个函数:
Function CanBeOpen(sPath As String) As Boolean
Dim wb As Workbook
On Error Resume Next
With Application
.EnableEvents = False
.DisplayAlerts = False
Set wb = .Workbooks.Open(sPath, False, True)
.SendKeys "~", True 'To close progressbar when opening
Select Case TypeName(wb)
Case Is = "Nothing"
CanBeOpen = False
Case Is = "Workbook"
CanBeOpen = True
Case Else
CanBeOpen = False
End Select
wb.Close savechanges:=False
.EnableEvents = True
.DisplayAlerts = True
End With
Set wb = Nothing
On Error GoTo 0
End Function
然而,这不是非常有效的方法。如果文件很大,打开它需要大量的时间。我想知道是否有人知道更快更优雅的解决方案。