how close excel object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrei Ryazanov

    how close excel object

    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.Applicat ion")
    boolXL = False
    Else
    Set objXL = CreateObject("E xcel.Applicatio n")
    boolXL = True
    End If


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

    ' objXL.Applicati on.Workbooks.Op en "c:\1.xls"
    'Set objActiveWkb = objXL.Applicati on.ActiveWorkbo ok

    'With objActiveWkb
    'Worksheets("Sh eet1").Range("A 2").Select
    'Worksheets("Sh eet1").Range("A 2").EntireRow.I nsert
    ' End With

    objActiveWkb.Cl ose savechanges:=Tr ue

    If boolXL Then objXL.Applicati on.QUIT

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


    With best regards, Stalker. E-mail: raa001@inbox.ru



  • Reggie

    #2
    Re: how close excel object

    Killing the object variables doesn't close the app. You need to explicitly
    close it
    objXL.Quit


    --
    Reggie

    "Half this game is 90% mental."

    ----------
    "Andrei Ryazanov" <raa1@inbox.r u> wrote in message
    news:bkekhm$rro t$1@ID-101406.news.uni-berlin.de...[color=blue]
    > 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.Applicat ion")
    > boolXL = False
    > Else
    > Set objXL = CreateObject("E xcel.Applicatio n")
    > boolXL = True
    > End If
    >
    >
    > when i adding next code
    > the excel.exe is not closed after code complete
    > why?
    >
    > ' objXL.Applicati on.Workbooks.Op en "c:\1.xls"
    > 'Set objActiveWkb = objXL.Applicati on.ActiveWorkbo ok
    >
    > 'With objActiveWkb
    > 'Worksheets("Sh eet1").Range("A 2").Select
    > 'Worksheets("Sh eet1").Range("A 2").EntireRow.I nsert
    > ' End With
    >
    > objActiveWkb.Cl ose savechanges:=Tr ue
    >
    > If boolXL Then objXL.Applicati on.QUIT
    >
    > Set objActiveWkb = Nothing: Set objXL = Nothing
    > ' MsgBox strWhat
    > End Sub
    >
    >
    > With best regards, Stalker. E-mail: raa001@inbox.ru
    >
    >
    >[/color]


    Comment

    Working...