Help with calling word reference from excel vba

K

KAM

I have vba code in excel that calls on some functions of Word.

I am using Office 2003 but my users are using either 2002 or 2003.

When I add the reference from the vba editor, I am able to choose:
Microsoft Word 11.0 Object Library (from my machine)

But when one of my users is using Office 2002 it needs a call to ver 10.0 of
the object Library.

How do I set up a reference to work on both 10.0 and 11.0? I do not have an
option to choose Microsoft Word 10.0 Object Library from mine since I am
running 2003 (11.0)

Any ideas on how I can set this up?

Thanks!
 
J

Jim Thomlinson

By choosing Word 11 as your reference you are doing something called early
binding (creating your reference at design time). You would be better off
creating your reference at run time. This is known as late binding. You loose
the intellisence but you gain the flexibility... Since you have already
written your code all you need to do is to change your objects from Word to
Object and remove your reference to the work application in the VBE. Use code
similar to what is posted below to create the Word app.

Sub test()
Dim appWord As Object

Set appWord = CreateObject("Word.Application")
appWord.Visible = True
End Sub
 
K

KAM

Thank you for that explanation!

If I don't really need Word open (I am only using a function available in
Word) then I would just create the object and not set it to visible as below?

Dim appWord As Object
Set appWord = CreateObject("Word.Application")
code here
Set appWord = Nothing

Is this how I would do it?

Thanks!
 
J

Jim Thomlinson

Yup... Just make sure you close the object before setting it to nothing.
Otherwise you will end up with an orphaned instance of Word running that is
not visible.
 
K

KAM

Got it working now! Thanks so much.

Jim Thomlinson said:
Yup... Just make sure you close the object before setting it to nothing.
Otherwise you will end up with an orphaned instance of Word running that is
not visible.
 
J

Jim Thomlinson

One thing I forgot to mention is that when you use late binding you can not
use any of the built in constants of Word. You need to traslate those to the
actual numerical values they represent...
 
K

KAM

OK, makes sense...but part of my code:

With appWd.Selection
.Tables(1).Select
.Rows.HeightRule = wdRowHeightAtLeast
.Rows.Height = InchesToPoints(0.25)
.HomeKey Unit:=wdStory
End With


It is only giving an error on the .rows.height = inchestopoints(0.25). I
would have thought the other items set to wd constants would have erred...Am
I missing something?
 
K

KAM

I have now switched all my constants to numbers and everything seems to
working OK now.

Thanks so much for your help!!
 

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