title: Check if Excel workbook is open from another Office 2010 App
body: <p>This continues from a previous <a href="https://stackoverflow.com/questions/11208805/object-trouble-accessing-excel-from-outlook">question</a>. I tried the suggested fix to check if an Excel file is open locally from an Outlook macro (Office 2010).</p>
  <pre><code>Public Sub UpdateFileIndex(ByVal FullFilePath As String, ByVal DocNo As String)
      Dim xlApp As Excel.Application
      Dim xlBook As Excel.Workbook
      Dim xlSheet As Excel.WorkSheet
      
      On Error Resume Next
      Set xlApp = GetObject(FullFilePath).Application
      Debug.Print &quot;Error = &quot; &amp; Err
  
      If Err.Number = 0 Then ' Workbook is open locally
          ' Do stuff
      ElseIf Err.Number = 429 Then ' Workbook is not open locally
          ' Do different stuff
      End If
  
      ' Do a bunch of other stuff
  End Sub
  </code></pre>
  <p>Now for open or closed files given by <code>FullFilePath</code> (e.g. <code>&quot;C:\Data\Data.xlsx&quot;</code>):</p>
  <ul>
  <li><code>Set xlApp = GetObject(FullFilePath).Application</code></li>
  </ul>
  <p>gives me 0 error either way. (i.e. it opens the file if it's not open.)</p>
  <ul>
  <li><code>Set xlApp = GetObject(Dir(FullFilePath)).Application</code></li>
  </ul>
  <p>gives me -214722120 for both cases. (Automation error)</p>
  <ul>
  <li><code>Set xlApp = GetObject(, &quot;Excel.Application&quot;)</code></li>
  </ul>
  <p>gives me 0 when open and 429 when not open. See below.</p>
  <ul>
  <li><code>Set xlApp = GetObject(Dir(FullFilePath), &quot;Excel.Application&quot;)</code></li>
  </ul>
  <p>gives me 432 for both cases. (File name or class name not found during Automation operation)</p>
  <ul>
  <li><code>Set xlApp = GetObject(FullFilePath, &quot;Excel.Application&quot;)</code></li>
  </ul>
  <p>gives me 432 for both cases.</p>
  <p>So the only case that works is the initially suggested fix (see link at top), which cannot find the file unless it's in the first instance of Excel open locally, which may not always be the case (i.e. it may be open in a second instance).</p>
  <p>Ultimately I'd like to check if the file is open on the network, and if it is check if it's open locally.</p>