Solved

VB.Net wrong Excel version opening

Posted on 2010-08-19
17
372 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now