- 积分
- 1281
- 明经币
- 个
- 注册时间
- 2017-8-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2024-4-13 20:45:53
|
显示全部楼层
Function IsFileInUse(FileName As String) As Boolean
Dim ff As Long, ErrNo As Long
On Error Resume Next
ff = FreeFile()
Open FileName For Input Lock Read As #ff
Close ff
ErrNo = Err
On Error GoTo 0
Select Case ErrNo
Case 0:
IsFileInUse = False
Case 70:
IsFileInUse = True
Case Else:
Error ErrNo
End Select
End Function
Public Sub CheckFileIsInuse()
Dim fn As String
fn = "D:\A.xlsx"
If dir(fn) = vbNullString Then MsgBox fn & vbNewLine & "not found, please check", vbCritical + vbOKOnly: Exit Sub
If IsFileInUse(fn) Then
MsgBox fn & vbNewLine & "is open already", vbCritical + vbOKOnly: Exit Sub
Else
MsgBox fn & vbNewLine & "no body open this file", vbInformation + vbOKOnly:
End If
End Sub |
|