Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck to see if Excel is open (from another Office 2010 App)
    primarykey
    data
    text
    <p>This question continues from a previous question I asked <a href="https://stackoverflow.com/questions/11208805/object-trouble-accessing-excel-from-outlook">here</a>. I'm using the suggested fix to check if an Excel file is open locally from an Outlook macro (Office 2010), but it's not working out as expected. Here's my code that's possibly failing. </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 "Error = " &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>"C:\Data\Data.xlsx"</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(, "Excel.Application")</code></li> </ul> <p>gives me 0 when open and 429 when not open. Aha?! See below.</p> <ul> <li><code>Set xlApp = GetObject(Dir(FullFilePath), "Excel.Application")</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, "Excel.Application")</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>Am I doing something wrong, or should I not be using this method to check? Ultimately I'd like to check if the file is open on the network, and if it is then check if it's open locally. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload