View Single Post
  #4   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
jack jack is offline
external usenet poster
 
Posts: 97
Default Excel automation: Why my code is hijacked?

Follow up.
The same happens when stepping through this code:
On Error Resume Next 'TEMPORARILY ignore errors
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application") === after
executing that line the code will not stop at the next line (End If)
End If

Interestingly, I am using the same code in another of my app and it does
work fine on the same computer!!!!
The Reference is set exactly to the same file and the general settings are
the same:
Option Explicit
Public WithEvents moExcelApp As Excel.Application
Dim moExcelWBk As Excel.Workbook
Dim moExcelWS As Excel.Worksheet

Jack

"Jack" <replyto@it wrote in message
...
Hello,
I have this routine to disconnect from Excel:

Public Sub XLDisconnectFromExcel()
If Not moExcelWS Is Nothing Then Set moExcelWS = Nothing
If Not moExcelApp Is Nothing Then Set moExcelApp = Nothing
End Sub

When the second line of that code is executed and moExcelApp is "Microsoft
Excel" then that line of code is executed properly (Excel.exe is process
terminated in Task Manager) but the code execution never returns after
that line. It just dissapears and subsequently not any other code is
executed.
What can be wrong?

To connect to Excel I use this code:
Set moExcelApp = GetObject(, "Excel.Application")
If moExcelApp Is Nothing Then
Set moExcelApp = CreateObject("Excel.Application")
End If

Jack