Results 1 to 9 of 9

Thread: Dynamic Referense [RESOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    24

    Angry Dynamic Referense [RESOLVED]

    Hi,

    is there a way to dynamically referense an Excel object into my project according to the version of the MS office the target machine uses ?

    My production pc uses Office 2003 whereas target machines might use Offiice 2000 or Office XP...

    Thanks
    Last edited by sonaht; Jan 24th, 2005 at 09:19 AM.
    Even Angels Fall.....

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dynamic Referense

    Whatever object library is available to you from your references selection will be what version you will be able to use in your application.

    If you are using Office 2003, there should be backward compatibility with lower versions. Have you tried running your app on a 2000 box or XP yet to see if you do have a problem? (your original post did not specifically say that you are running into issues. The inference from your question is that you believe you might.)

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Dynamic Referense

    Yes, there are a few things to change in your code:

    * The first is to replace the Excel types with Object, so if you have:
    VB Code:
    1. Dim xlApp as Excel.Application
    2. Dim xlBook as Excel.Workbook
    3. ...
    you need to change it to:
    VB Code:
    1. Dim xlApp as Object
    2. Dim xlBook as Object
    3. ...

    * The next change is to replace the initialisation of the object, so if you have:
    VB Code:
    1. Set xlApp = New Excel.Application
    you should replace it with:
    VB Code:
    1. Set xlApp = CreateObject("Excel.Application")

    * Remove "Excel object Library" from the list in Project References

    * The final change is to replace any constants from the Excel library, or define them in your code (there is download at www.msdn.microsoft.com called wc0993.exe that has a module with them all defined, which you can simply add to your project).

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    24

    Re: Dynamic Referense

    U are absolutely spot on.

    I think i might have problems.... that'w why I asked..

    I will try to compile using Office 2000 reference and see if there is a problem with later versions.

    I just wanted to know if someone knew something on the matter...

    thanks
    Even Angels Fall.....

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2004
    Posts
    24

    Re: Dynamic Referense

    si_the_geek I will try that ......


    it looks exectly what i was after .....


    thanks
    Even Angels Fall.....

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Dynamic Referense

    Quote Originally Posted by Hack
    Whatever object library is available to you from your references selection will be what version you will be able to use in your application.

    If you are using Office 2003, there should be backward compatibility with lower versions.
    Not quite true I'm afraid, there were some changes in Office 2003 which mean initiating the object for earlier versions has some major issues, however once that is done almost everything seems ok.

    Using my method means that whatever version is installed (95/97 and up) can be used without any change to the code (of course any features added to Office XP will fail if you try them on Office 97).

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Dynamic Referense

    Quote Originally Posted by Hack
    Originally Posted by Hack
    Whatever object library is available to you from your references selection will be what version you will be able to use in your application.

    If you are using Office 2003, there should be backward compatibility with lower versions.
    Quote Originally Posted by si_the_geek
    Not quite true I'm afraid, there were some changes in Office 2003 which mean initiating the object for earlier versions has some major issues, however once that is done almost everything seems ok.
    Thanks for the info si, it has been awhile since I've done anything with any of the office products. I'm not running 2003. We still have the Office 2002 product suite. Were the changes you referenced first introduced in 2003, or might they be present in 2002 as well?

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Dynamic Referense

    erm.. I can't remember, it hasn't been an issue for me as I have never been able to guarantee my users will have exactly the same versions (and don't want to re-compile a load of programs each time we upgrade anyway ), so I've always used the method above.

    I'm pretty sure that the issue can be spotted by the item that is added to an installation package, if there is "Excel.exe" (rather than a tlb) the issue arises.


    I would recommend always using the method I posted, as it allows unexpected changes to occur in the installation base without effecting your programs

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Thumbs up Re: Dynamic Referense

    Quote Originally Posted by si_the_geek
    erm.. I can't remember, it hasn't been an issue for me as I have never been able to guarantee my users will have exactly the same versions (and don't want to re-compile a load of programs each time we upgrade anyway ), so I've always used the method above.

    I'm pretty sure that the issue can be spotted by the item that is added to an installation package, if there is "Excel.exe" (rather than a tlb) the issue arises.


    I would recommend always using the method I posted, as it allows unexpected changes to occur in the installation base without effecting your programs
    Excellent advice!! (Who says you can't teach an old Hack new tricks! )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width