Results 1 to 6 of 6

Thread: xl not closing

  1. #1

    Thread Starter
    Lively Member Bolerophone's Avatar
    Join Date
    Dec 2003
    Location
    Himalayas
    Posts
    123

    Resolved xl not closing

    I'm creating a xl worksheet i VB6 using the following code.


    Code:
    Public objXL As New Excel.Application
    Public wbXL As New Excel.Workbook
    Public wsXL As New Excel.Worksheet
    
    
        Set wbXL = Workbooks.Open(App.Path & "\test.xls") 
        Set wsXL = wbXL.Worksheets.Add(, Worksheets(1))
    i close these in this manner.


    Code:
    wbXL.Save
        Set wsXL = Nothing
        wbXL.Close False
        Set wbXL = Nothing
        Set objXL = Nothing
    After executing above code, when i open the task manager there still is an instance of xl process in memory.

    i hv win xp, vb6 SP5 , office2k. can any1 help

    -amresh-
    Last edited by Bolerophone; Nov 26th, 2004 at 01:56 AM.
    Jobs: "Do u want to sell colored sugar water or change the world?"

    Get Firefox Now!!!
    Mendhak leaving town.

  2. #2
    Fanatic Member Bombdrop's Avatar
    Join Date
    Apr 2001
    Location
    St Helens, England, UK
    Posts
    667
    This is a a pain yopu would think that by setting the object to nothing it would destory the Excel application but you have to quite the application also.

    VB Code:
    1. bXL.Save
    2.     Set wsXL = Nothing
    3.     wbXL.Close False
    4.     Set wbXL = Nothing
    5.     'This is what we need
    6.     objXL.Quit
    7.     Set objXL = Nothing

    Hope this helps!!

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: xl not closing

    There is also something else which might cause issues along these lines, which I would strongly recommend changing.

    You are referencing Excel based objects, but are not specifying any parent objects, therefore VB will make assumptions (which could easily be incorrect, and may not even reference Excel at all!).

    What you should have is this:
    VB Code:
    1. Public objXL As New Excel.Application
    2. Public wbXL As New Excel.Workbook
    3. Public wsXL As New Excel.Worksheet
    4.  
    5.  
    6.     Set wbXL = [b]objXL.[/b]Workbooks.Open(App.Path & "\test.xls")
    7.     Set wsXL = wbXL.Worksheets.Add(, [b]wbXL.[/b]Worksheets(1))

  4. #4

    Thread Starter
    Lively Member Bolerophone's Avatar
    Join Date
    Dec 2003
    Location
    Himalayas
    Posts
    123
    thanks. I will try these methods.

    -Amresh-
    Jobs: "Do u want to sell colored sugar water or change the world?"

    Get Firefox Now!!!
    Mendhak leaving town.

  5. #5

    Thread Starter
    Lively Member Bolerophone's Avatar
    Join Date
    Dec 2003
    Location
    Himalayas
    Posts
    123

    Thumbs up resolved

    I tried both the methods. However the excel application instance in the task manager does go away however only when I exit my application and not when the function calling objXL.Quit exits.

    Well it works for me. Still any insights will be great.
    Jobs: "Do u want to sell colored sugar water or change the world?"

    Get Firefox Now!!!
    Mendhak leaving town.

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    maybe set the value of the function to nothing?

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