Compile Errors Multiple Versions Word

J

J Pettigrew

Hello,

Now I can write my procedure that tells word to do one
command if its Word 97/2000, and another if it is Word
2002/2003, I am now finding compile errors when running
this code in Word 97.

The code is formatting a table, and obviously, because
tables have changed, the commands have changed between
the versions.

When it is run in Word 97, a compile error appears when
it looks through the code that is meant for the Word
2002/03 versions.

Is there any way I can get Word 97 to ignore the code
designed for later versions of Word?

Thanks in advance
JP
 
W

Word Heretic

G'day "J Pettigrew" <[email protected]>,

Yes. Use the #IF compiler directives.

Steve Hudson - Word Heretic
Want a hyperlinked index? S/W R&D? See WordHeretic.com

steve from wordheretic.com (Email replies require payment)


J Pettigrew reckoned:
 
P

Pete Bennett

A slightly easier (and readable) alternative is to write and test your VBA
code in both version of Word and then put the code into one template.

After your check for what version of Word you're running
(Int(Application.Version)), you create an Object type variabe and assign the
application to it. Then use the properties of the object in exactly the same
way as you use the Application object (which you mostly use by inference
anyway)...

Dim objOff97 as Object
Dim objOff2000 as Object

If WordVersion = 97 then
Set objOff97 = Application
objOff97.ActiveDocument.Range.Tables(1).Office97.Specific.Code
set objOff97 = Nothing
Else
Set objOff2000 = Application
objOff2000.ActiveDocument.Range.Tables(1).Office2000.Specific.Code
set objOff2000 = Nothing
End If

It would be more efficient if you limit the use of the Object to the actual
lines of version specific code. But you'll find that the code is more
readable then using a host of compiler directives, and of course, it'll
compile and run natively.

Pete.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top