Results 1 to 9 of 9

Thread: Help on closing Excell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Talking

    I have written an app that uses excell to produce reports, but there is an error when closing it down, it stays in memory which is shown in the task bar.

    Is there any way in which i can remove it, or better still totally destroy it.

    here is the last few lines on my code....


    objexcel.ActiveWorkbook.[Close] False
    objexcel.Application.Quit
    Set objexcel = Nothing

    Thanks from Rohan

  2. #2
    Junior Member
    Join Date
    Jun 2000
    Location
    Manchester, England
    Posts
    28

    Closing Excel

    If you don't need excel open at all (and you don't mind closing any sessions of Excel the user is running!) you could try calling the GetObject() function as in:

    set objExcel = GetObject("Excel.Application")

    If you omit the "path" argument from the call, GetObject returns an existing instance of the requested object. If there is an error, there are no instances running (visible or not) so you can be sure that your object has been destroyed successfully. If no error occurs, you can then call the Quit method on the object to close it and then set the object to nothing. Keep repeating this until an error occurs, clear the error and continue.

    Hope this helps.
    We watch in reverence as Narcissus is turned to a flower.

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    Public objExcel as .... and then put your close and nothings in the exit part of your code ..works for me.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Location
    Wellington NZ
    Posts
    153

    Thumbs down Hi there thank you ,

    I know that this may be a bit stupid but do you have any codeed examples that you could show me

    Rohan

  5. #5
    Junior Member
    Join Date
    Jun 2000
    Location
    Manchester, England
    Posts
    28
    Here goes...

    On Error Resume Next

    Dim objExcel as Object

    Do Until Err.Number <> 0
    Set objExcel = GetObject(, "Excel.Application")
    If Err.Number = 0 Then
    objExcel.Application.Quit
    Set objExcel = Nothing
    End If
    Loop
    We watch in reverence as Narcissus is turned to a flower.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    run a macro inside an exel object example

    Private Sub Form_Load()
    'put this code inside the form load event of the Application
    'change the file name and macro name to reflect your file and macro
    'this will open Excel and run the macro
    '
    'create and object (Excel SpreadSheet)
    Dim oXL As Object
    Set oXL = CreateObject("Excel.Application")

    ' Open the workbook that contains the macro to run.
    oXL.Workbooks.open "C:\My Documents\try.xls"
    '
    'as object opens invisible, make visible if needed, if not omit
    'the line oXL.visible=true
    '
    oXL.Visible = True
    '
    ' Run the macro.
    oXL.Application.Run "try.xls!myMacro"
    '
    ' Quit Microsoft Excel.
    oXL.Quit
    '
    ' Free the object from memory.
    Set oXL = Nothing

    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    HeSaidJoe,
    please tell me you have a code for me too.

    I just want one simple thing. If there is data in cell (A1) on sheet ( sheet1) then the workbook cannot be closed. And if that's too easy for you, then also the workbook cannot be saved (in the same case).


    SO, what do you say?
    Thanks.
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  8. #8
    Frenzied Member wengang's Avatar
    Join Date
    Mar 2000
    Location
    Beijing, China
    Posts
    1,604
    oh yeah, I mean in an Excel macro, not VB.


    THANKS

    Wengang
    Wen Gang, Programmer
    VB6, QB, HTML, ASP, VBScript, Visual C++, Java

  9. #9
    Addicted Member
    Join Date
    Jan 2000
    Location
    Fresno, California, USA
    Posts
    195
    And if all of that stuff doesn't work, try changing this line:
    objexcel.ActiveWorkbook.[Close] False
    to:
    objexcel.Workbooks.Close

    Sometimes (always) the default blank workbook loads up and doesn't have anywhere else to go when you close the active workbook.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width