Sub TestFile()
If IsFileLocked( sFile) Then
MsgBox "LOCKED"
Else
MsgBox "available"
End If
End Sub
Public Function IsFileLocked(psFileName As String) As Boolean
On Error Resume Next
' If the file is already opened by another process,
' and the specified type of access is not allowed,
' the Open operation fails and an error occurs.
Open psFileName For Binary Access Read Write Lock Read Write As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
' Display the error number and description.
'MsgBox "Error #" & Str(Err.Number) & " - " & Err.Description
IsFileLocked = True
Err.Clear
End If
End Function