我在这里找到了一些代码来检查工作簿是否打开,但我得到了
Run-time Error '70': Permission Denied if the file is open.
我不确定如何处理此错误或修改代码以处理此问题。
Sub Sample()
Dim Ret
Ret = IsWorkBookOpen("I:\RJB\Juan's Project\Summary Sheet.xlsm")
If Ret = True Then
MsgBox "File is open"
Else
MsgBox "File is Closed"
End If
End Sub
Function IsWorkBookOpen(FileName As String)
Dim ff As Long, ErrNo As Long
On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff 'This line is highlighted when the crash occurs
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0: IsWorkBookOpen = False
Case 70: IsWorkBookOpen = True
Case Else: Error ErrNo
End Select
End Function