title: Checking if a file is open
body: <p>For the life of me I can't see why my coding does not work.  The following coding does give me a message if the file is open in notepad, but it doesn't if the file is open in word or excel?</p>
  
  <pre><code> Dim apps = 0
      Dim Process() As Process = System.Diagnostics.Process.GetProcesses
      For Each p As Process In Process
          If p.MainWindowTitle.ToString.Contains("test") Then
              If p.ProcessName = "notepad" Then
                  MsgBox("test file is open in notepad")
                  apps += 1
              ElseIf p.ProcessName = "winword" Then
                  MsgBox("test file is open in word")
                  apps += 1
              ElseIf p.ProcessName = "excel" Then
                  MsgBox("test file is open in excel")
                  apps += 1
              End If
          End If
      Next
  
      If apps = 0 Then
          'run my code
      End If
  </code></pre>
  
  <p>It just doesn't seem to check word and excel but both the following snippets of coding work?</p>
  
  <pre><code>   Dim Process2() As Process = System.Diagnostics.Process.GetProcessesByName("winword")
      For Each p As Process In Process2
          If p.MainWindowTitle.Contains("test") Then
              MsgBox("test file is open in word")
          End If
      Next
  </code></pre>
  
  <p>and</p>
  
  <pre><code>   Dim Process2() As Process = System.Diagnostics.Process.GetProcessesByName("excel")
      For Each p As Process In Process2
          If p.MainWindowTitle.Contains("test") Then
              MsgBox("test file is open in excel")
          End If
      Next
  </code></pre>