Solved

VB.Net wrong Excel version opening

Posted on 2010-08-19
17
374 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

786 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