Programming for different Word versions

R

Ron

I've developed a VB6.0 application which calls a
Word.Application.
I need to distribute this to client's with versions of
Word different than my development system (i.e. my app
references my Word.olb library).

Can a reference to a client's word library be added at
runtime, or is it possible to install different word
libraries on my development computer, so I can reference
the appropriate library and create version-specific
applications?

Many thanks
 
J

Jezebel

First: develop your app for the lowest version of Word you are prepared to
deal with. Make sure you have a copy of this library on your machine, for
testing purposes.

Second: once you've got your app running and debugged, switch to late
binding. Remove the reference to the Word library. Replace all word type
declarations with "as object". Instantiate your Word application using
CreateObject or GetObject. This way you get whatever version of Word the
user has installed. You can use the Version property to test, eg

Dim wrdApp as object
Set wrdApp = CreateObject("Word.Application")
If wrdApp.Version < 9 then
err.Raise Description:="Can't use this version of Word..."
End if
 
G

Guest

Just what I needed, thanks again!
-----Original Message-----
First: develop your app for the lowest version of Word you are prepared to
deal with. Make sure you have a copy of this library on your machine, for
testing purposes.

Second: once you've got your app running and debugged, switch to late
binding. Remove the reference to the Word library. Replace all word type
declarations with "as object". Instantiate your Word application using
CreateObject or GetObject. This way you get whatever version of Word the
user has installed. You can use the Version property to test, eg

Dim wrdApp as object
Set wrdApp = CreateObject("Word.Application")
If wrdApp.Version < 9 then
err.Raise Description:="Can't use this version of Word..."
End if







.
 
H

Howard Kaikow

Compile the program using EARLY binding with a reference to the libraries
for the earliest version of Office you wish to support.
 
J

Jezebel

Howard, the trouble with that approach is that if the user has a later
version of Word installed, they don't HAVE the earlier library. So of
necessity, VBA substitutes the version that the user DOES have -- which,
since it's not the version you compiled with, won't necessarily function as
expected, or at all. Word doesn't guarantee backward compatability at
library level.
 
H

Howard Kaikow

Jezebel said:
Howard, the trouble with that approach is that if the user has a later
version of Word installed, they don't HAVE the earlier library. So of
necessity, VBA substitutes the version that the user DOES have -- which,
since it's not the version you compiled with, won't necessarily function as
expected, or at all. Word doesn't guarantee backward compatability at
library level.

If you compile using the earliest library, then Word will use the correct
library.

This is documented in many places.
 
T

Tom Winter

I have to agree with Howard here. When you run a VB6 app that was compiled
with a reference to a specific type library, the running executable does not
reference the type library. The information it needed from the type library
was compiled into the executable. Things like the CLSIDs and GUIDs of the
interfaces it uses. It doesn't matter what "library" is installed on the end
user's machine. The reason people usually run into problems with this kind
of thing is because they're not real careful about checking versions at run
time. If you are careful, there is no reason you can't use early binding. If
you are REALLY careful, you can even compile with a reference to a newer
type library and it will still work with an older version of Word. I have
done this with a very large application. It was compiled against Word 2000,
but runs fine on Word 97-only systems, with early binding. I can explain
this in detail if you would like.

One thing to note is that the original poster talked about VB6, not VBA (in
Word, etc.). VBA does re-reference the newer version of type libraries and
things like that. VB6 is a different animal.
 
J

Jezebel

Only if the correct library is available. Which, with Word, is often not the
case. (And copyright prohibits your distributing it.)

And then your app falls over.
 
T

Tom Winter

Uh guys, rememner, in a compiled VB6 app, the type library doesn't even need
to be there. The app doesn't actually reference it at run-time.
 
J

Jezebel

ah-hem ... ever tried it?



Tom Winter said:
Uh guys, rememner, in a compiled VB6 app, the type library doesn't even
need to be there. The app doesn't actually reference it at run-time.
 
T

Tom Winter

OK, I do take that back. After some testing using auditing on the file, a
VB6 project does access the OLB file. I stand corrected.

But that still doesn't change the fact that you can compile using early
binding against an older version the type library and have things work just
fine with a newer version at run-time. I have tried that, many times. Can
you give a specific example of when that wouldn't work?

In regards to your statement, "Word doesn't guarantee backward compatability
at library level", Microsoft states the opposite.

In this article:

INFO: Writing Automation Clients for Multiple Office Versions
http://support.microsoft.com/default.aspx?scid=kb;EN-US;244167

Microsoft states, "Office applications that are tested and compiled with
earlier versions of a type library continue to work, unchanged, when end
users of your product upgrade their Office installations to a more recent
version. In this way Office provides backward compatibility".

They are in effect saying that your program using early binding can forward
to newer versions of Word, but (generally) can't go backwards to older
versions.
 
J

Jezebel

fine with a newer version at run-time. I have tried that, many times. Can
you give a specific example of when that wouldn't work?


Create a VB app, compiled with Word.8. Run it on a machine that has only
Word.11. Failure.
 
T

Tom Winter

OK, I took the following VB6 application, with a reference to MSWORD8.OLB
(the only Word type library registered on the machine), compiled it. It ran
OK on Word 97/8.0. Took it to a machine with only Word 2003/11.0. It worked
OK.
--
Tom Winter
[email protected]


Option Explicit

Sub Main()

Dim oWord As Word.Application

Dim oDocument As Word.Document

Set oWord = GetObject(, "Word.Application")

Set oDocument = oWord.Documents.Add()

oDocument.Content.InsertAfter "Test"

End Sub
 
J

Jezebel

You're in no position to make that assertion, Howard. That's just being
dogmatic. Which is unbecoming of you.
 
Top