CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Join Date
    Jan 2003
    Location
    London/Moscow
    Posts
    60

    closing excel application

    Hi all,

    How do i close xlapplication. I try to use

    dim xlApp as new excel.application

    xlapp.quit

    but the process seems to be hanging there until i quit from my app.

    also how do i make it visible in .NET. In vb 6 it was just
    xlApp.Visible = true it does not work with .Net

    Thanks

  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878
    after you quit excel
    xlapp.quit
    you have to set object to nothing
    xlapp = Nothing

    That will kill the excel app
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Jan 2003
    Location
    London/Moscow
    Posts
    60
    i've tryed it, doesn't work. it is still three event after i quit my app.

    i have to create large number of xlapps and at the end they all there hanging...

  4. #4
    Join Date
    Feb 2003
    Posts
    44
    Is there a component that I need to add to be able to issue the command:

    dim xlApp as new excel.application

    If I try this it is an error, because excel.application is not defined. Any thoughts?

  5. #5
    Join Date
    Nov 2002
    Posts
    34
    you need to add reference / project/add reference/com/ microsoft excel ....

  6. #6
    Join Date
    Feb 2003
    Location
    NY
    Posts
    2
    You may want to try getting the new COM objects from microsoft that are for office. This may help...

  7. #7
    Join Date
    Nov 2002
    Posts
    34
    Are they not meant to come with office you install. I'm using office 2000 but tried office xp. the same problem.

    Does it work for you? if you check task manager before closing your application.

    I start to think that this is ms **** automatic garbage collector problem.

  8. #8
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878
    You can prevent Excel hanging around by explicitly cleaning up any Excel
    objects you instantiated with Marshal.ReleaseComObject and then invoking the
    ..NET garbage collecter before exiting.

    Something like:

    While (Marshal.ReleaseComObject(m_excelObj) <> 0) ' Repeat until no
    more COM references
    End While
    m_excelObj = nothing
    ..... repeat for any other Excel objects allocated

    ' Invoke garbage collector before termination
    GC.Collect()
    GC.WaitForPendingFinalizers()
    Iouri Boutchkine
    [email protected]

  9. #9
    Join Date
    Nov 2002
    Posts
    34
    Thanks Iouri, it worked for excel,

    now the same doesnot work for outlook. also if i try to quit outlook from olapp.quit i get

    'Quit' is ambiguous across the inherited interfaces 'Outlook._Application' and 'Outlook.ApplicationEvents_Event'.

  10. #10
    Join Date
    Feb 2003
    Posts
    44
    When I use that code to close out my Excel Appliction, it seam so work fine. byut when I try to open up the file I created, somtimes it opens up excel, but I can't veiw the cells. I can only see the toolbars, and where the cells should be I can see my desktop. Also any thoughts on how to caclulate 2 cells, and put the total in a different cell. And formating a cell, so it is a percentage, stuff liek that.

  11. #11
    Join Date
    Jan 2000
    Posts
    264
    Funny you mentioned that you can see your desktop because just yesterday when I attempted to open an excel spreadsheet, it did the same thing - no matter which worksheet.

    Fix: make sure that excel.exe is not running in your processes in Task Manager. If it is, end the process and try opening your spreadsheet again. That should fix that problem.

  12. #12
    Join Date
    Feb 2003
    Posts
    44
    With VB.NET what code would I use to chage the Fill Color of a cell, Freeze Panes, calculate cells, and add borders? Is their a good web site for any of this? Gknierim, I closed the Excel.EXE and it worked fine. What had happed is that I gave an invaild file name to SaveAS, so the program never got all the way through closing Excel. Thanks.

    BJG

  13. #13
    Join Date
    Feb 2003
    Posts
    44
    In my Task Manager..why won't my Excel.EXE close until I close stop running my VB project.

  14. #14
    Join Date
    Jan 2000
    Posts
    264
    I think that you could use the following to get you started. These are just a few:

    Code:
    Dim oSheet as Excel.WorkSheet
    
    'For a border - specify start and end for range
    oSheet.Range("A1", "D12").BorderAround()
    
    'For bold etc..
    oSheet.Range("A1", "D12").Font.Bold = True
    Look at the range property in your help for the Excel object and it will give you several examples on how to format your cells.

    HTH,
    Greg

  15. #15
    Join Date
    Feb 2003
    Posts
    44
    Here is my code for creating and closing Excle through VB.NET. If I close or exit my VB Applictaion I can use excel fine, and EXCEL.exe is deleted from my Task Manager. What I want to do is be able to use excel while my VB Application is still running. So how do I get that EXCEL.exe to be end from Task Manager.


    Dim xlapp As New Excel.Application()
    xlapp.Workbooks.Add()

    ''' Do a bunch of random things here(adding totals, writing to cells, etc.)

    xlapp.Workbooks(1).Close(False)
    xlapp.Quit()

    While(System.Runtime.InteropServices.Marshal.ReleaseComObject(xlapp) <> 0) ' Repeat until no more COM references
    End While

    xlapp = Nothing
    ' Invoke garbage collector before termination
    GC.Collect()
    GC.WaitForPendingFinalizers()

    PLEASE HELP!
    BJG

Page 1 of 2 12 LastLast

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