Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stuck in Word automation hell

Status
Not open for further replies.

asilverblatt

Programmer
Jan 13, 2010
10
US
Earlier this year, I developed a VB 6 application to automatically generate letters as Microsoft Word documents. After extensive testing and debugging, it worked flawlessly on my Win XP development machine. Now, while I'm attempting to troubleshoot a run-time error the end users are having, the same application throws this error on my machine:

-2147417851
Automation error
The server threw an exception.

when it executes the "Set WordDoc =" statement shown below. This happens regardless of whether I'm running the compiled .EXE or in the VB IDE, and regardless of whether an instance of Word is already running. The document whose name is stored in the constant BHRSLetterName exists and can be opened manually without any problem.

Does anyone have a clue as to why this would suddenly stopped working, and how to correct it? Thanks in advance.

[the following code is in a standard module]
Public Const BHRSLetterName = "\\Parker\BHRSLetters\BHRS Welcome Letter.doc"

[the following code is in a form module]
Private Sub DoLetters(...)
...
Dim WordApp As New Word.Application
...
CreateLetter ..., WordApp, ...
...
End Sub

Private Sub CreateLetter(..., WordApp As Word.Application, ...)
Dim WordDoc As Word.Document
...
Set WordDoc = WordApp.Documents.Open(BHRSLetterName, , True)
...
End Sub
 
Could be something else however your code is using early binding so will be bound to the version of MS Word used during development so...
>Earlier this year, I developed a VB 6 application...
Is the same version of Word in use now?
>error the end users are having...
Are they using the same version of Word you used during the original development?
 
Since my original posting, I've tried using late binding (changing both WordApp and WordDoc to type Object), using a local Word document that I just created (and clearly have rights to) which has no spaces in the file spec, Word.Application.12 instead of Word.Application (that won't compile), and putting a three second delay into DoLetters() before it calls CreateLetter(). All of this is to no avail - it still chokes on the same statement with the same error, despite the fact that it runs fine on everyone else's machine, and previously ran fine on mine.

Any other ideas?
 
Could be you got the late bound code right however this works for me;

Private Sub Command1_Click()

'Late bound
FileName$ = "\\Parker\BHRSLetters\BHRS Welcome Letter.doc"

With CreateObject("Word.Application")
.Documents.Open FileName$, , True
.Visible = True
End With

End Sub

Does it work for you?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top