Sunday, March 23, 2008

Launching Excel to view Files from VB.NET

Launching Excel from VB.NET to view a file (.xls, .csv, .etc) has a seemingly simple solution:

Process.Start("c:\temp\test.csv")

However, this simple solution has a problem. After Excel is running, it does not respond to this type of command anymore. Excel has to be closed (killed) before you can successfully call Start again with any file that is associated with Excel.

I see several different approaches to this problem:

http://vbnetsample.blogspot.com/2007/08/start-and-kill-process.html

http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.windowsforms/topic17364.aspx

http://www.devx.com/dotnet/Article/7914

There is also a totally different approach using Excel's automation to open the file:

http://www.webmaster-talk.com/net-programming-forum/85020-open-excel-file-in-vb-net.html

http://support.microsoft.com/default.aspx/kb/301982

http://support.microsoft.com/kb/302094

http://www.thescripts.com/forum/thread348936.html

No comments: