View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Yury Lobanov Yury Lobanov is offline
external usenet poster
 
Posts: 8
Default How to determine if instance of Excel is running

Hi, Keith.

Is it possible to run my own Excel instance, so that no one can bind to my
instance?

Yury.

"Keith Willshaw" сообщил/сообщила в
новостях следующее: ...


The easiest way is to attempt to use automation to connect to
an existing instance and only create a new instance if that fails.
Its is possible to use the win32 API's to get a list of running
processes but its complex.


The following function will attach to a current instance
or create a new one

Public Function open_excel (xlapp as Excel.Application) as Boolean


' First lets find out if Excel is already running

On Error GoTo excel_start:
Set xlapp = GetObject(, "Excel.Application")

' Make sure Excel is visible
xlapp.Application.Visible = True

open_excel = True
Exit Function

' Excel not running error handler
excel_start:

On Error GoTo No_excel_err:
Set xlapp = New excel.Application

open_excel = True
xlapp.Application.UserControl = True

= "Starting Excel"
Splash_scrn.Show
Exit Function

' Excel not found error handler
No_excel_err:
msg = "Fatal Error - Unable to start Excel " & Chr$(10) & _
"Please check your installation"
MsgBox msg, vbCritical
open_excel = False
Exit Function

End Function


Keith