View Single Post
 
Old 05-27-2014, 04:23 AM
Sorcerer13 Sorcerer13 is offline Windows Vista Office 2010 32bit
Novice
 
Join Date: Sep 2012
Location: God's Own County
Posts: 16
Sorcerer13 is on a distinguished road
Default Detecting an active instance of Excel from Word VBA

Hi guys....
I am using the following code to check if Excel is currently active on a User's PC prior to opening another Excel Workbook.
Code:
 
'In a "Globals" module"

 Public gxlApp                       As Excel.Application
 Public gbooExcelIsRunning           As Boolean

'In the "detection" module

  On Error Resume Next
  Set gxlApp = GetObject(, "Excel.Application")
  If Err.Number <> 0 Then
    gbooExcelIsRunning = False
    Set gxlApp = New Excel.Application
   Else
    gbooExcelIsRunning = True
  End If
  On Error GoTo 0
However, this code (based on a Microsoft example) ALWAYS says that Excel is running, even when it definitely wasn't when the code was invoked.
It appears that my code actually invokes Excel (via the GetObject process??).
Can any kind soul correct my code to DETECT Excel, rather than INVOKE Excel?
I know the end result is to create an instance of Excel (which this does), but I'm trying to ensure that, later on in the code, if Excel was running to just close the new Workbook, but if Excel wasn't running, I'd like to close the Workbook and shut Excel down.
Reply With Quote