PDA

View Full Version : IsFileOpen Error "53" in 2003



defcon_3
01-10-2012, 07:14 PM
This code works with ms 2007, however i wonder why it doesnt work on ms 2003? It always give me error that say "File not found: Error 53". Any another workaround to make this work on ms2003? Thanks


Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long

On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0

Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr '<< error appear here
End Select

End Function

Sub test()
If Not IsFileOpen("test.xls") Then
Workbooks.Open "test.xls"
End If
End Sub

Kenneth Hobs
01-10-2012, 08:43 PM
Function IsWorkbookOpen(stName As String) As Boolean
Dim Wkb As Workbook
On Error Resume Next ' In Case it isn't Open
Set Wkb = Workbooks(stName)
If Not Wkb Is Nothing Then IsWorkbookOpen = True
'Boolean Function assumed To be False unless Set To True
End Function

defcon_3
01-10-2012, 10:41 PM
This solves my query. Thanks a lot Mr. Hobs. :)