Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

launch Excel from WinForm app

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BrenB - 25 Jun 2007 22:49 GMT
I want to open an Excel doc from my .NET 2.0 WinForm application.

I have a list of UNC path names of Excel documents a user might want
to open.

The way I'm doing it now works, but when the user closes Excel, it is
still running; I can see it in the list of processes in TaskManager.

My WinForm app open the document this way:

   Dim pathname As String = ListBox1.SelectedItem.ToString()
   Dim excelApp As Excel.Application
   excelApp = New Excel.Application()
   excelApp.Workbooks.Open(pathname)
   excelApp.Visible = True
   excelApp = Nothing

Even though I am setting excelApp to nothing, my WinForm app is
holding on to Excel after the user closes it.

Is there a better approach to opening Excel so that it will close when
the user closes the Excel window?
Mike - 25 Jun 2007 23:24 GMT
Have you tried                
myWorkBook.Close(false,Type.Missing,Type.Missing);
Marshal.ReleaseComObject(myWorkBook);

> I want to open an Excel doc from my .NET 2.0 WinForm application.
>
[quoted text clipped - 18 lines]
> Is there a better approach to opening Excel so that it will close when
> the user closes the Excel window?
Robbe Morris - MVP C# - 26 Jun 2007 03:16 GMT
You have got to set literally every object reference
including the sheet, the workbook, and the application
object to null in your finally clause.

The sample in this article will show you:

http://www.eggheadcafe.com/articles/20021012.asp

Signature

Robbe Morris
EggHeadCafe.com
http://www.eggheadcafe.com/articles/adonet_source_code_generator.asp

>I want to open an Excel doc from my .NET 2.0 WinForm application.
>
[quoted text clipped - 18 lines]
> Is there a better approach to opening Excel so that it will close when
> the user closes the Excel window?
BrenB - 26 Jun 2007 18:16 GMT
Thank you both, Robbe and Mike, for responding to my post. Your
suggestions worked for me.

I nulled all my objects after calling the ReleaseComObjects method on
them.

I did not close the workbooks or quit the app in my code. When I
closed Excel using its user interface, I saw its process end in Task
Manager.

I appreciate the help.

Bren

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.