how stop excel.exe after createobject

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)
 
J

Joe Fallon

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top