我想确定某个工作簿是否已由用户或网络上的其他用户打开,文件扩展名可能位于.xls,.xlsx或.xlsm
我尝试过使用下面的功能,但这需要知道文件扩展名,否则我会收到53错误代码
Function IsFileOpen(fileName As String)
Dim fileNum As Integer
Dim errNum As Integer
On Error Resume Next
fileNum = FreeFile()
Open fileName For Input Lock Read As #fileNum
Close fileNum
errNum = Err
On Error GoTo 0
Select Case errNum
Case 0 'errNum = 0 means no errors, therefore file closed
IsFileOpen = False
Case 70 'errNum = 70 means the file is already open
IsFileOpen = True
Case Else 'Something else went wrong
IsFileOpen = True
End Select