Calling Word (Ugh)

S

Scupper

I am working on adapting a process currently handled by VBA functions in
a Word template, moving to a VB.NET app that calls Word only when
necessary to manipulate documents (essentially, it is calling up a
dataset, writing it to a Word-readable mergefile, and then opening up
one of a number of templates and merging the data).

The application is working well on my development machine, which has
Word 2000 installed.

However ... I need it to work even if the user only has Word 97, and
there it becomes tricky.

This code works fine on the development machine:

'----------------------------------------------
Const ERR_APP_NOTRUNNING As Long = 429

Dim oWord As Word.ApplicationClass
Dim oDoc As Word.DocumentClass

Try
oWord = GetObject(, "Word.ApplicationClass")
Catch When Err.Number = ERR_APP_NOTRUNNING
oWord = New Word.ApplicationClass
End Try

With oWord
oDoc = .Documents.Add(strPath & strTemplate, , , True)
.ActiveDocument.MailMerge.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters

'... and so on

'-----------------------------------------------

But on a machine running Word 97, I get a type-91, "Object reference not
set to instance of an object" error on the "oDoc = ..." line.

An instance of Word is opening up, but I cannot seem to do anything with
it.

My questions:

Is there a better way to do this?
Is there a good way to support multiple potential external app versions?

Any and all help in this would be much appreciated, as this project has
gone well beyond its expected development time.
 
C

CJ Taylor

Could be the versioning of the system. If you want it to be that backwards
compatible then you might want to read up on the office 97 object model (if
you can find it =)) and make sure that it supports Doc.Add

Could be an interface that was added later down the road and isn't
compatible... Lots of things. =)

-CJ
 
O

One Handed Man [ OHM# ]

The object is probably called something else in Word97. You'll need to check
the object hierarchy for that version and then you will find the object is
not in the reference you have already added to your project.

Regards - OHM#

I am working on adapting a process currently handled by VBA functions
in a Word template, moving to a VB.NET app that calls Word only when
necessary to manipulate documents (essentially, it is calling up a
dataset, writing it to a Word-readable mergefile, and then opening up
one of a number of templates and merging the data).

The application is working well on my development machine, which has
Word 2000 installed.

However ... I need it to work even if the user only has Word 97, and
there it becomes tricky.

This code works fine on the development machine:

'----------------------------------------------
Const ERR_APP_NOTRUNNING As Long = 429

Dim oWord As Word.ApplicationClass
Dim oDoc As Word.DocumentClass

Try
oWord = GetObject(, "Word.ApplicationClass")
Catch When Err.Number = ERR_APP_NOTRUNNING
oWord = New Word.ApplicationClass
End Try

With oWord
oDoc = .Documents.Add(strPath & strTemplate, , , True)
.ActiveDocument.MailMerge.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters

'... and so on

'-----------------------------------------------

But on a machine running Word 97, I get a type-91, "Object reference
not set to instance of an object" error on the "oDoc = ..." line.

An instance of Word is opening up, but I cannot seem to do anything
with it.

My questions:

Is there a better way to do this?
Is there a good way to support multiple potential external app
versions?

Any and all help in this would be much appreciated, as this project
has gone well beyond its expected development time.

Regards - OHM# (e-mail address removed)
 
M

Mike Bulava

Try late binding to Word rather then referencing it(Kill the reference, and
declare oDoc and oWord as object).. I've had nothing but problems using
Multiple Versions of Office Products when early binding. And I think some
one once told me that once you compile on a station with one version of
Office the program will not function on any other version of office..
 

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