How to dynamically add/change Reference?

J

Joe HM

Hello -

I have some code in Excel where I open up a Word Document ...
Set lFileObject = CreateObject("Scripting.FileSystemObject")
Dim lWordApplication As Word.Application
Dim lWordDocument As Word.Document
....

I have the Microsoft Word 11.0 Object Library added under Tools >
References to make this work. The problem is that at my company there
are still some machines with Word 10.0. Right now I need two different
versions of the Excel file, once with the reference to 11.0 and one
with the reference to 10.0.

Is there a way I can automatically add the reference based on which
version of Word is installed?

Thanks!
Joe
 
G

Guest

You don't need to make the explicit reference. Try something more like this...

Sub test()
Dim wrdApp As Object

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

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