My program needs to send some information to an existing word document.
I can get it to work, but encounter a problem which I can't seem to fix.
I am using VB5 and MS Word97
I use the following code to open the word document and send the
information across to a table in the word document.
(I have the Word 8.0 Object Library selected in the Project References.)
Dim wrdDoc as Word.Document
Set wrdDoc = GetObject(sMyWordDocument)
wrdDoc.Parent.Visible = True
Set MyTable = ActiveDocument.Tables(1)
'And so on until all the info is in
Set wrdDoc = Nothing
Set MyTable = Nothing
This all works fine. The VB app opens word, and the correct document is
displayed, and all the information is inserted. If, however, I close
MS-Word (just closing the document, and leaving Word open has no
effect), then run the above procedure again from the same instance of
the VB app, Word opens again, but not the document, and I get the
Run-Time error '-2147023174 (800706ba)':
and the code halts at the following line of code:
I suspect that the way I am opening Word is the problem, but so far it's
the only way I can get Word to open, and the for the document to be
displayed. Also the user needs to be able to edit the word document, so
I can't close it from the VB app with the Application-Quit method.
What am I doing wrong, and how can I fix it?
A Second question - does anybody know a good (preferably on-line)
resource for integrating VB with Office 97. I need to do it quite
often, and so far all the VB documentation I have on the subject is VERY
Thank you in advance.