Results 1 to 5 of 5

Thread: Different Versions of Office Causing Headaches

  1. #1

    Thread Starter
    Hyperactive Member Vladamir's Avatar
    Join Date
    Feb 2012
    Location
    Miami, FL
    Posts
    486

    Different Versions of Office Causing Headaches

    Well here is another weekend approaching which means I will be working on my system in my home office instead of the desktop at my office. And the version of MS Office I have at home is 2007 vs 2003 here. Of course this means that any code I develop at my home has to be edited extensively in order to work at my office (References, path names, etc...) The pathnames I'm know I'm stuck with so I use variables for those which makes changing them out no big deal. But changing out references is another thing. I thought that somewhere I read that there is a way to overcome this. Am I just wishfully thinking or did I perhaps really see something like this at one point?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: Different Versions of Office Causing Headaches

    there is a way... it's called late binding + requires Option Strict to be off.
    Shaggy Hiker has an example + probably further advice, in the vb.net codebank

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Different Versions of Office Causing Headaches

    Yeah. Look for my name and Excel and you should find the base class I use for Excel activity. It makes use of late binding.

    Basically, you build and test your program with references, as you have done. You then remove the reference to Excel (or whatever office product). Naturally, this results in a load of errors because of a bunch of unrecognized types. Set Option Strict OFF for the file with the errors, and change the unrecognized types to type Object.

    What this does is tells the compiler, essentially, "Ignore the fact that Object doesn't have these methods. By the time this code runs, the actual objects WILL have the methods." This will work for most things in Excel, but not all things. The basic stuff like Workbooks, Worksheets, and so on didn't change methods or method signatures. Some things did change, though. One thing I found was that the pivot tables changes between 2003 and 2007, so code that uses pivot tables in 2003 won't work for 2007, and vice versa. In that Excel class there is a function (which I got from RobDogg888) that can be called to tell you which version you are using at runtime, so you can make a different version for 2003 and 2007 for those few things that changes. If you have already been changing from 2003 to 2007 and back, you probably know whether or not any of the code needs to be different for those versions.
    My usual boring signature: Nothing

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,510

    Re: Different Versions of Office Causing Headaches

    I have .Net 2010 and I set the "Embed Interop" to true and this seems to work. This way you can leave Option Strict on.
    Read this http://msdn.microsoft.com/en-us/libr...7478.aspx#Y726

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,104

    Re: Different Versions of Office Causing Headaches

    I'm not sure what advantages there are for one over the other. The painful thing about late binding is certainly making any changes. I've never tried it the other way.
    My usual boring signature: Nothing

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