CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Excel in VB

  1. #1
    Guest

    Excel in VB

    I am usings EXCEL automation control in VB6.I open two instances of excel. After using excel I set the excel sheets =nothing, workbook =nothing and excel.application =nothing.

    After the code is executed only one of the excel objects go out of memory. I still see it in the Task manager, although all the 2 excel applications are closed and exited. Any suggestions?



  2. #2
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Excel in VB

    You could use GetObject("Excel.Application") for your second instance of Excel. I've found Excel to be not quite as Automation friendly as it could be when it come to starting and shutting down. I usually try to grab an already running Excel instance and use that if possible.

    Dim fMadeByMe as Boolean
    Dim oExcelApp as Excel.Application
    fMadeByMe = false
    set oExcelApp = GetObject("Excel.Application")
    If oExcelApp is nothing then
    'Excel was not already running
    set oExcelApp = new Excel.Application
    fMadeByMe = true 'set the flag
    End If
    'Do your spreadsheet stuff here and close
    'your workbook
    If fMadeByMe = true then
    'Only close the instance of Excel
    'if you made it
    oExcelApp.Close
    End If
    set oExcelApp = 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

Featured