思路是当文件以锁定方式打开时,如果文件已经打开就会出错。

- Sub test()
- If IsFileOpened("d:\accountlist.xls") Then
- MsgBox "文件已经打开!"
- End If
- End Sub
- Function IsFileOpened(ByVal FileName As String) As Boolean
- IsFileOpened = True
-
- ' 使用锁定方式打开文件
- On Error GoTo ErrTrap
- Open FileName For Binary Lock Read Write As #1
- IsFileOpened = False
- Close #1
- Exit Function
-
- ErrTrap:
- Close #1
- On Error GoTo 0
- End Function
|