how stop excel.exe after createobject

  • Thread starter Thread starter Stalker
  • Start date Start date
S

Stalker

Hello, All!
i try the following text from mvps.org

Sub sTestXL()
Dim objXL As Object
Dim strWhat As String, boolXL As Boolean
Dim objActiveWkb As Object

If fIsAppRunning("Excel") Then
Set objXL = GetObject(, "Excel.Application")
boolXL = False
Else
Set objXL = CreateObject("Excel.Application")
boolXL = True
End If


when i adding next code
the excel.exe is not closed after code complete
why?

' objXL.Application.Workbooks.Open "c:\1.xls"
'Set objActiveWkb = objXL.Application.ActiveWorkbook

'With objActiveWkb
'Worksheets("Sheet1").Range("A2").Select
'Worksheets("Sheet1").Range("A2").EntireRow.Insert
' End With

objActiveWkb.Close savechanges:=True

If boolXL Then objXL.Application.QUIT

Set objActiveWkb = Nothing: Set objXL = Nothing
' MsgBox strWhat
End Sub


With best regards, Stalker. E-mail: (e-mail address removed)
 
This is a tricky topic.
But basically you have to create each variable very carefully and then
destroy them all before you end.
If you miss one (easy to do because some are created behind the scenes for
you if you are not careful) then Excel will hang open.
 
Back
Top