The trick is to use late binding. Instead of adding a project reference to
the Word library and using 'Dim WordApp as Word.Application', omit the
library reference and use:
Dim WordApp as object
Set WordApp = CreateObject("Word.Application")
That returns a reference to whatever version of Word the user has on their
system. It makes programming a little harder because you don't get the
intellisense assistance -- I use the library method for development, then
change to CreateObject for final testing and compilation.
You might also need to check the version number and work differently or
abort if the version of Word is too old ...
If WordApp.Version = 8 then
... [code for Word 97]
elseif WordApp.Version > 8 then
... [code for Word 2000 or later]
end if
-- or --
If WordApp.Version < 9 then
Err.Raise Number:=errBadVersion, Description:= "This application
requires Word 2000 or later"
end if
Dan said:
Thank you for your helpful explanation. As far as I know, there was
nothing else going on when my program was running, and I know we didn't
switch to Word manually and close it.
Your comment about different versions of Word is a definite possibility.
How can I make my code work with any recent version of Word? Does the object
library for Word on the system where I do my development limit me to working
only with that version of Word on every other system?