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.
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.