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
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