Word automation and backwards compatability
I have a Windows application which opens a document in Word 2003.
Its fairly straight forward and works well enough.
The problem is that I have to make this compatable with Office 2003, XP and 2007.
How do you guys go about this. I have access to all these versions here at the office but have no idea how to implement this. I take it I have to look into late binding.
Any tips are most welcome.
Thanks In Advance:wave:
Re: Word automation and backwards compatability
Firt of all use late binding (Search on it)
Second use Office XP as your testcase(most stuff is backward compatible)
Good Luck,
because 2007 has large object changes
I do have a sourcecode to read the installed versions of Word out of the register somewhere, but that's in VB6.0 so I doubt it would be helpfull
Re: Word automation and backwards compatability
Thanks
I am looking at late binding now but I'll admit to being confused.
Re: Word automation and backwards compatability
Quote:
Originally Posted by venerable bede
I have a Windows application which opens a document in Word 2003.
Its fairly straight forward and works well enough.
The problem is that I have to make this compatable with Office 2003, XP and 2007.
How do you guys go about this. I have access to all these versions here at the office but have no idea how to implement this. I take it I have to look into late binding.
Any tips are most welcome.
Thanks In Advance:wave:
Hi,
If you're concernd with supporting Office 2003 and Office 2007, then change your reference from version 12. That should fix it.
Wkr,
sparrow1
Re: Word automation and backwards compatability
What will that fix? Surely that wont help if the objects and classes etc in the Office 2007 PIAs arent all identical to the Office 2003 and Office XP ones... which I doubt they are.
Re: Word automation and backwards compatability
No,
In the end you do not want to have any reference at all.
For Developing sake reference the lowest version and use interop like:
The Microsoft Word 10.0 Object Library dll in the Com Tab
The you can write stuff like:
Code:
Dim WordApp As Microsoft.Office.Interop.Word.Application
Dim WordDoc As New Microsoft.Office.Interop.Word.Document
WordApp = new Microsoft.Office.Interop.Word.Application
WordDoc = WordApp.Documents.Open(path_to_file_here)
After Writing al you need to do change all Variables to Objects and Use CreateObject Like
Code:
Dim WordApp As Object
Dim WordDoc As Object
Obj = CreateObject("Word.Application")
WordDoc = WordApp.Documents.Open(path_to_file_here)
And Don't Forget to remove the reference to "Microsoft Word 10.0 Object Library "
Re: Word automation and backwards compatability
For those 3 versions you would have more trouble writting separate code to handle 2007 as its defaults are different from 2002/2003.
Use Late Binding and check the version before proceeding farther in your code so if they are using Word 97/2000 you can handle it as you desire by either notifying them or by kicking them out and requesting the proper version.
VB6/Office Automation (also Late Binding):
http://www.vbforums.com/showthread.php?t=406640
Determine version:
http://www.vbforums.com/showthread.php?t=402020
Re: Word automation and backwards compatability
Quote:
Originally Posted by Dnereb
No,
In the end you do not want to have any reference at all.
I dont get it, I thought you had to have those references in for that code to work? If thats not the case, then why does the IDE not even let you compile if the reference isnt there?
Re: Word automation and backwards compatability
I think he means no references to Office/Word
Re: Word automation and backwards compatability
Ohh right, so he doesnt mean references as in project references - just literally refering to specific versions of Word/Office?
Re: Word automation and backwards compatability
Just project references to Word/Office. When you Late Bind you dont use any references to the library that you are using. In this case its Word but when you add a reference to Word, a reference to Office is also added because Word is dependant upon the base Office libraries.
Re: Word automation and backwards compatability
Ah i see, I think I need to do some reading up on Late Binding then, sounds interesting/useful
Re: Word automation and backwards compatability
Check out my FAQ item on Late Binding in VB.NET for more and some code examples.
http://www.vbforums.com/showthread.php?t=406637
Re: Word automation and backwards compatability
Yes I just meant the reference I mentioned in the post.
The key to achieve this is this line:
Obj = CreateObject("Word.Application")
This way you can creat an object that isn't referenced.
You need to use a try catch block to catch errors if office/Word isn't installed and probably You'll need to use try catch as well if you have to use 2007 specific features and write XP/2003 alternatives.
Tip: Write some code in Word VBA and use it's objectbrowser if you want to figure out how to Word object is used, it's a bit of a monster designwise.