Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB.Net wrong Excel version opening

Posted on 2010-08-19
17
375 Views
Last Modified: 2012-05-10
Hi

I have a Windows form in which I want to open a file in Excel 2002.

It must be 2002 that starts, not 2003 (due to a change in the 2003 algorithm for LINEST)

Unfortunately this code starts Excel 2003, not 2002

    xlsApp = New Excel.Application
    xlsApp.Visible = True
    xlsWB = xlsApp.Workbooks.Open(path)
   
The project references are to Excel 10.0 DLL's

Help please in forcing 2002 to open, thank-you in advance
0
Comment
Question by:rwallacej
  • 5
  • 5
  • 3
  • +2
17 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 33473515
The only way to do that (assuming you have multiple versions installed) is to Shell the excel.exe for the version you want.
0
 
LVL 3

Expert Comment

by:LDH
ID: 33473570
Try referring to the Excel 9.0 DLL's..
0
 

Author Comment

by:rwallacej
ID: 33473571
ok so how do I do that?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33473581
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 33473611
In .Net I don't know. In VB6 you would just use Shell:
Shell """C:\path to msofficeXP\excel.exe"" ""c:\path to workbook\.xls""", vbnormalfocus
and you can then use GetObject with the workbook name to get a reference to that instance of Excel.




0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33473629
My Project -References In .net
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 33473646
References won't work. If you have multiple versions, the default one will start regardless unless you run the specific executable.
0
 

Author Comment

by:rwallacej
ID: 33473648
the references are set to 10.0.....this is Excel 2002 from what I have read

tried changing from new Excel.Application to be

   xlsApp = CreateObject("Excel.Application")

but still got 2003 starting
0
 

Author Comment

by:rwallacej
ID: 33473651
the Shell idea sounds best, if I knew how it worked in .Net
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 250 total points
ID: 33473714
A quick google seems to imply that System.Diagnostics.Process.Start does the same thing (but doesn't take the second parameter for window style). See this page: http://www.devx.com/dotnet/Article/7914
HTH

Rory
0
 
LVL 5

Expert Comment

by:DerZauberer
ID: 33473826
not sure if that might help, but try

xlsApp = CreateObject("Excel.Application.9")

It actually depends on what objects are registered in the windows registry under "HKEY_CLASSES_ROOT\Excel.Application*"

0
 

Author Comment

by:rwallacej
ID: 33475867
trying

xlsApp = CreateObject("Excel.Application.9")

gives error "Cannot create ActiveX component"

.10 starts Excel 2003

under windows registry there is
Excel.Application
Excel.Application.10
Excel.Application.11
0
 

Author Comment

by:rwallacej
ID: 33475964
Try referring to the Excel 9.0 DLL's..
-->I only have 5, 10 & 11 DLLs, not 9
picking 5 means compile error "cannot create new instance of interface"
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 33476719
10 is the correct version for 2002. You cannot use CreateObject or New Excel.Application. It will not work.
0
 
LVL 5

Expert Comment

by:DerZauberer
ID: 33509928
In VB.NET the "Shell" function still exists in namespace Microsoft.VisualBasic.Comaptibility

You can use it in a similar way like rorya suggested to launch the correct Excel.exe application.
0
 
LVL 5

Assisted Solution

by:DerZauberer
DerZauberer earned 250 total points
ID: 33510068
Well there is a more .NET like way to start applications and you might need to access the application-object somehow.

You can go like this:

System.Diagnostics.Process process = System.Diagnostics.Process.Start(@"C:\Program Files\<path to your excel version>\Excel.exe");
int processId = process.Id;

Afterwards use the function AccessibleObjectFromWindow to gain access to the object model.

You can look up the documentation here:

http://msdn.microsoft.com/en-us/library/dd317978%28VS.85%29.aspx
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question