Hello Tirren,
Here is a more thorough test macro to determine if a file of any kind is open.
'Written: December 24, 2007
'Author: Leith Ross
'Summary: Tests if a file is already open.
Function IsFileOpen(filename As String, filepath As String) As Boolean
Dim ErrData As String
Dim Errnum As Integer
Dim Filenum As Integer
If Right(filepath, 1) = "\" Then filepath = Left(filepath, Len(filepath) - 1)
If filepath <> CurDir() Then filename = filepath & "\" & filename
On Error Resume Next
Filenum = FreeFile()
' Attempt to open the file and lock it.
' If the mode is Append, Binary, Output, or Random
' the file is created if it doesn't exist.
Open filename For Input Lock Read As #Filenum
Close Filenum
Errnum = Err.Number
ErrData = Err.Description
On Error GoTo 0
' Check to see which error occurred.
Select Case Errnum
' No error occurred.
' File is NOT already open by another user.
Case 0
IsFileOpen = False
' Error number for "Permission Denied."
' File is already opened by another user.
Case 70
IsFileOpen = True
' Another error occurred.
Case Else
MsgBox "The follow error occurred: Error (" & Errnum & ") - " _
& ErrData & vbCrLf _
& Chr$(34) & filename & Chr$(34), vbExclamation, "Is File Open"
End Select
End Function
Sincerely,
Leith Ross
Bookmarks