Solved

VB.Net wrong Excel version opening

Posted on 2010-08-19
17
377 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel 2013 Find and copy duplicates to a new worksheet 6 37
Need help with another query 10 39
Nested forach loop to linq 3 29
Compare data between two sheets in Excel 6 33
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…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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