"anandmr" wrote in message
...
I am trying to use excel from Visual basic.
I am having the probelm when a second instance of the VB is opened. The
sheet will hidden behind sme application and I am able to see only the
tool bars which are on top. I have closed all the workbooks before
opening another.
Is there any method to know if a excel instance is running. Please help
with a solution.
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