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

How to CreateObject() of a specific version

Posted on 2004-08-02
11
1,075 Views
Last Modified: 2012-06-22
I have both Office 2000 and Office 2003 installed on Windows XP.

I have an Access 2000 application that uses OLE with Excel 2000.

Since I installed 2003, when I instanciate the Excel object, it always instanciate a 2003 version.

I reference Excel 9.0 library

This is the code I use:

dim oXL as Excel.Application
set oXL = createobject("Excel.Application.9")
debug.print oXL.Version     ==> 11.0 !!

How can I force opening the version 9 instead ?

Thanks
0
Comment
Question by:ragoran
  • 6
  • 4
11 Comments
 
LVL 34

Expert Comment

by:flavo
ID: 11700483
To force it youll need to use early binding

Add a refrence to the Excel  Obj Lib 9.0 (and not 11.0) from tools refreces in vb window

Then decrelare it like

Dim xlApp as excel.application

Then

Set xlApp = new excel.application

 (also faster to use early binding than late binding, but if you copy to a pc without 2000, its going to fail when you use early biding)

idea???

Dave
0
 
LVL 34

Expert Comment

by:flavo
ID: 11700504
Early v late

Early binding
- Need to add a refrence (Tools - refrences)
- Faster
- Will fail if the exact refrence (dll) is not on the pc
- use like Dim xl as Excel.Application
             Set xl = New excel.application

Late Binding
- slower
- Will work on for example Excel 97 if you develop on Excel 2000 (if same properties / methods were present)
- Use like - Dim xl as object
                set xl = createobjecy("excel.application")

Dave
0
 
LVL 34

Expert Comment

by:flavo
ID: 11700508
ohh.. didnt read your Q properly sorry..
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 34

Expert Comment

by:flavo
ID: 11700511
why are you trying to use 2000 may i ask???
0
 
LVL 16

Expert Comment

by:GreymanMSC
ID: 11700621
 This is the code I use:
 
  dim oXL as Excel.Application  
  set oXL = createobject("Excel.Application.9")
  debug.print oXL.Version     ==> 11.0 !!
 
Duh!  First, oXL is dimentioned as Excel.Application class.   It will always be an object of that class and the version is set in the early binding References.  Second, the late binding function CreateObject is looking for a registered class of the format appname.objectClass which, despite you use of .9, is likely going to be the same version of Excel.Application as set in your references.  If it wasn't, your code would fail, because you can't set an object of one class to an object of another class unless the second class implements the first.  Third, you're trying to mix late and early binding!
 
Listen to Dave's advice on binding.
0
 
LVL 14

Author Comment

by:ragoran
ID: 11704104
Hello all and thanks for the comments.

Few clarifications and answers.

Background:

The application was written in Access/Excel 2000.  It is run from my client PC to prepare spreadsheets that are distributed throughout his organisation.  His IT department has decided to roll out Office 2003.  This won't happen overnight as they have '000 of PC to upgrade.  So I was asked to ensure that the spreadsheet did work properly (lots of code behind) with both version of Excel.  Eventually, my client will also be migrated to Office 2003, but until then, the application itself has to run with Excel 2000.

So on my PC, I have both version of Office installed.  Good thing, there were few minor glitches to fix into the spreadsheet.  But when I started the Access 2000 application to create new spreadsheets, it bombs on a line because the version 11 model has changes some methods.  I could, and eventually would convert everything to 2003, but I can't right now as my client still runs 2000.  But I do have to test on my PC first.


Early/Late binding:

I know about early and late binding.  This is only defined by te way you declare your variable: either as a specific class (early) or as a gineric object (late).  It as nothing to do with how you instanciate your object, with new, createobject() or getobject().  These methods may involved  other differences, but has no impact on early Vs Late binding.  If the variable has been defined as a specific class, then early binding suggest that the compiler knows that and 1) will enforce assignements of same class (or implements of) and 2) will already have the "path" to find methods and properties code.

   The first code was:

   dim oXL as Excel.Application
   set oXL = new Excel.Application

   But then I could not specified the version suffix.  So I tried with a CreateObject() method instead.


References:
My application does reference excel v9 library.  I will tried to remove then recreate the reference.  I will also test no reference at all and running on late binding only but I don't like it...

This is a project I am working from home.  I will do more test tonight and give you some feedback then.


Thanks
0
 
LVL 14

Author Comment

by:ragoran
ID: 11711341
I am back,

I tried to recreate the reference to no avail.  Still create a version 11 object, either thru the set oXl =- new .. or with CreateObject().

I did a little digging.  The registry contains class entries for Excel.application, Excel.Application.11 and Excel.application.9 but they all point to the same CLSID entry which is for Excel 11.  I think I found the reason why I can't get an instance of Excel 9, even if the application is still installed and operational if started manually.

Of course, I can't find the CLSID entry for Excel 9 anymore in my registry.  Is it something I could Import from another PC that has only Excel 9 install and then have the Excel.application.9 class point to this CLSID ?

Michel

0
 
LVL 34

Accepted Solution

by:
flavo earned 250 total points
ID: 11711353
you could maybe try copy the dll / lib from a 2000 and regiter it.

If you use late binding then it should work on the 2000 version anyway (as long as the properties / methods etc havent changed).   why all the fuss??

Dave
0
 
LVL 14

Author Comment

by:ragoran
ID: 11711625
Dave,

As I said, even with Late Binding, it is always Excel 2003 which instanciate.  The problem, is that my application uses a property that does not exist anymore with 2003, so the application bombs.  

I got the CLSID defintion for Excel 9 application from another PC, change the ID number to sometihing else (I know, risky), ensure the path for the application was ok then imported the keys in my registry.  I then change the CLSID for excel.application.9 to the imported one.  I then try to instanciate my object, holding my breath...  the application hang. I must be missing something here...


I may have to change the code and test the actual version whenever I encounter version specific instructions... sight

if val(oXl.version) < 11 then
   ' old way
else
   ' new way
end if
0
 
LVL 14

Author Comment

by:ragoran
ID: 11711830
I found one more thing (for future readers).

The property that was not working is VBE (a reference to the Visual Basic Editor).  After doing some searching on EE, I found out that since Office XP, there is a new security switch that, by default, will block access to VB project in excel and word.  When I turn the switch off (actually set it to Trust), then the property start working.

The setting is named "trust access to Visual Basic Project".

I still haven't found how to instanciate a specific version, but the actual problem is no longer there, so I will close this question.

Dave: thanks for your help.
0
 
LVL 34

Expert Comment

by:flavo
ID: 11711881
Sorry i couldnt be of more assistance, i only have 97.  (yes work is back in the stone ages)

its going to cost too much to update / test / fix several hundred Access db's, plus cost of upgrading over 5000 pc's to office 2000 / xp.

Good luck with the rest of your app mate

Dave
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
On Key Down Access 2010 6 41
Record with #Error 8 33
Access vs. Filemaker Pro vs. SQL Server 4 61
Run Stored Procedure uisng ADO 5 20
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

861 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