Public Function IsFileOpen(sFile As Variant) As Boolean Dim fFile As Integer Dim msg As String fFile = FreeFile() On Error GoTo ErrOpen Open sFile For Binary Lock Read Write As fFile Close fFile Exit Function ErrOpen: If Err.Number <> 70 Then msg = "Error # " & Err.Number & " was generated by " _ & Err.Source & Chr(13) & Err.Description MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext Else IsFileOpen = True End If End Function
Dim fFile As Integer
Dim msg As String
fFile = FreeFile()
On Error GoTo ErrOpen
Open sFile For Binary Lock Read Write As fFile
Close fFile
Exit Function
ErrOpen: If Err.Number <> 70 Then
msg = "Error # " & Err.Number & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
Else
IsFileOpen = True
End If
End Function