Launching Excel from VB.Net - Figured it out.

drebo

Diamond Member
Feb 24, 2006
7,034
1
81
So, I've got a project to do. I query a database based on some parameters entered by the user, display the data in a DataGridView, let the user play with it a bit, he selects data and those selected rows go into another DataGridView where the user can play with it some more, user repeats the search and select process until he's done.

Now, the user clicks the "Export" button. Excel template file loads, fields are populated based on selected rows.

Now, here's the tricky part. I need this programmatically modified Excel workbook to launch into Excel. I can save the workbook. I can launch a web browser with the web-generated version. I can Print Preview the workbook.

But, I cannot for the life of me get the workbook to open in Excel.

Can anyone tell me which method I need to use to launch Excel with this workbook pre-loaded? I would love you to bits and pieces!

Edit: Figured it out... excel.Visible = true... I swear... Arg!
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
Actually, not making it visible to begin with will speed up any processing you do, because it doesn't have to immediately redraw your results.

And you should use CreateObject() (new Excel.Applicaton) and not GetObject() [or equivalent] so that way you can manage all the instances that your program uses, and simply address workbook 0 of that application instance. Plus you can just make your own instance of it invisible, because the user may have other Excel docs he wants open. Otherwise, you are just complicating it for yourself.
 

techfuzz

Diamond Member
Feb 11, 2001
3,107
0
76
xtknight is right, make it invisible. There is a huge difference in processing speed that be gained.

techfuzz
 

drebo

Diamond Member
Feb 24, 2006
7,034
1
81
It is invisible while I'm doing work in it. However, it needs to be visible at the end (user has some manual information needed to be entered).