|
-
May 31st, 2013, 03:16 PM
#1
Thread Starter
Hyperactive Member
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?
-
May 31st, 2013, 03:21 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
May 31st, 2013, 03:31 PM
#3
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
 
-
May 31st, 2013, 03:36 PM
#4
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
-
May 31st, 2013, 03:42 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|