title: How to test if a .txt file is already open by anyone?
body: <p>I am trying to test if a .txt or .ini file is open already by anyone. I have several versions of IsFileOpen. Here is one taken directly from <a href="http://www.cpearson.com/excel/ISFILEOPEN.ASPX" rel="nofollow noreferrer">http://www.cpearson.com/excel/ISFILEOPEN.ASPX</a></p>
  
  <pre><code>Option Explicit
  Option Compare Text
  Public Function isfileopen_test(FileName As String, _
      Optional ResultOnBadFile As Variant) As Variant
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  ' IsFileOpen_test
  ' This function determines whether a the file named by FileName is
  ' open by another process. The fuction returns True if the file is open
  ' or False if the file is not open. If the file named by FileName does
  ' not exist or if FileName is not a valid file name, the result returned
  ' if equal to the value of ResultOnBadFile if that parameter is provided.xd
  ' If ResultOnBadFile is not passed in, and FileName does not exist or
  ' is an invalid file name, the result is False.
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  
  Dim FileNum As Integer
  Dim ErrNum As Integer
  Dim V As Variant
  
  On Error Resume Next
  
  ''''''''''''''''''''''''''''''''''''''''''''
  ' If we were passed in an empty string,
  ' there is no file to test so return FALSE.
  ''''''''''''''''''''''''''''''''''''''''''''
  If VBA.Trim(FileName) = vbNullString Then
      If IsMissing(ResultOnBadFile) = True Then
          isfileopen_test = False
      Else
          isfileopen_test = ResultOnBadFile
      End If
      Exit Function
  End If
  
  ''''''''''''''''''''''''''''''''''''''''''''
  ' if the file doesn't exist, it isn't open
  ' so get out now
  ''''''''''''''''''''''''''''''''''''''''''''
  V = Dir(FileName, vbNormal)
  If IsError(V) = True Then
      ' syntactically bad file name
      If IsMissing(ResultOnBadFile) = True Then
          isfileopen_test = False
      Else
          isfileopen_test = ResultOnBadFile
      End If
      Exit Function
  ElseIf V = vbNullString Then
      ' file doesn't exist.
      If IsMissing(ResultOnBadFile) = True Then
          isfileopen_test = False
      Else
          isfileopen_test = ResultOnBadFile
      End If
      Exit Function
  End If
  
  FileNum = FreeFile()
  '''''''''''''''''''''''''''''''''''''''
  ' Attempt to open the file and lock it.
  '''''''''''''''''''''''''''''''''''''''
  Err.Clear
  Open FileName For Input Lock Read As #FileNum
  ErrNum = Err.Number
  ''''''''''''''''''''
  ' Close the file.
  ''''''''''''''''''''
  Close FileNum
  On Error GoTo 0
  
  ''''''''''''''''''''''''''''''''''''''
  ' Check to see which error occurred.
  ''''''''''''''''''''''''''''''''''''''
  Select Case ErrNum
      Case 0
          ''''''''''''''''''''''''''''''''''''''''''''
          ' No error occurred.
          ' File is NOT already open by another user.
          ''''''''''''''''''''''''''''''''''''''''''''
          isfileopen_test = False
      Case 70
          ''''''''''''''''''''''''''''''''''''''''''''
          ' Error number for "Permission Denied."
          ' File is already opened by another user.
          ''''''''''''''''''''''''''''''''''''''''''''
          isfileopen_test = True
      Case Else
          ''''''''''''''''''''''''''''''''''''''''''''
          ' Another error occurred. Assume open.
          ''''''''''''''''''''''''''''''''''''''''''''
          isfileopen_test = True
  End Select
  
  End Function
  </code></pre>
  
  <p>I need to do this via VBA. I can't get it to work for a .txt or .ini file. How can I check if a txt or ini file is already open by someone on the network?</p>
  
  <p>Edit: It returns false for txt and ini files whether they are open or not.</p>
  
  <p>If you are so inclined, I am attempting to build a distributive computing system on a clients network. I've never done this before and I am looking to keep it as simple as possible, so I was thinking of communicating via txt files. MSMQ looks good, but it looks like a long learning curve. I've already read all of the posts on stackoverflow regarding distributive computing.</p>