网上下的,试了一下还可以
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lClose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
' 判断某文件是否在使用中
Public Function IsFileAlreadyOpen(FileName As String) As Boolean
Dim hFile As Long
Dim lastErr As Long
hFile = -1 ' 初始化文件句柄.
lastErr = 0
hFile = lOpen(FileName, &H10)
If hFile = -1 Then ' 文件是否能正确打开并可共享
lastErr = Err.LastDllError
Else
lClose (hFile)
End If
IsFileAlreadyOpen = (hFile = -1) And (lastErr = 32)
End Function
Private Sub Command1_Click()
Dim strFileName As String
strFileName = "d:\\050304_chengji.xls" ' 你的文件
If IsFileAlreadyOpen(strFileName) Then
MsgBox "指定文件已打开"
Else
MsgBox "指定文件未打开"
End If
End Sub