Error handler not working

Hi,

I've written a function below to check if a file is allready open or not.

Function IsWorkBookOpen(FileName As String) As Boolean

  Dim Ret

  

  Dim ff As Long

  ErrNo As Long

  ff = FreeFile()

  On Error Resume Next

  Open FileName For Input Lock Read As #ff

  Close ff

  ErrNo = Err

  On Error GoTo 0

  

  Exit Function

  

'''''''''''''''

'Error handler'

'''''''''''''''

  If Err.Number = 0 Then

  IsWorkBookOpen = False

  ElseIf Err.Number = 70 Then

  IsWorkBookOpen = True

  End If

  

  End Function

If it's open I get error number 70 if it's not I get error 0.

When I run the code and I get to [Open FileName For Input Lock Read As #ff] VBA stops the macro to tell me I have error number 70.

What am I doing wrong?

Kind regards,

Willie

SolidworksApi macros