I encounter a problem whenever I automate Excel from any other MS Package. I am using Windows NT and Excel 97.
I create an instance of Excel by calling the following function in an attempt to determine if Excel is already open…
‘EXCELGET – Use the FINDWINDOW API to determine if Excel is already open
Public Function EXCELGet() As Excel.Application
Dim hWnd As Long
On Error GoTo EXCEL_Error
hWnd = FindWindow(“XLMAIN”, 0)
If hWnd = 0 Then
Set EXCELGet = New Excel.Application
Else
Set EXCELGet = Excel.Application
End If
End Function
When it is a new instance of Excel being created, there is no problem and as long as I keep that instance open, Excel can continue to be automated. However, if I shut the Excel application (from Excel), the instance does not seem to been taken out of process. ‘Excel.exe’ remains in the ‘Task List’ and any further attempts to automate it result in the Toolbar/menus of Excel showing but you cannot view the workbook or sheets.
If you manually terminate the Excel.exe process, further attempts to automate Excel result in error ‘The RPC Server is unavailable’. It’s only when you shut the application/database controlling Excel that the process is removed and Excel can be automated again.
Has anyone encountered this problem, as it is driving me crazy…!?