I am having a problem with Microsoft Word Automation. My program needs to start Word 97 to generate a report. The first time I click the button everything works fine. I disable the button at this point until the first process completes. I am creating the object and then closing the object I am sure of this. The second time I click the button, I get an error message 426 Remote Server Unavailable. I look at the NT Task Manager and there is no instance of the program running but it seems to lose track of something. What the heck is this about. I have tried this several ways, and nothing works. I also checked out Q188546 which describes part of the problem, I tried that resolution and it makes it even worse. I am using Windows NT 4.0. I have watched the Task Manager, this instance of word created during the first click of the button is removed from the list of tasks. Any ideas would be most appreciated.
Here is the code:
Dim DiskFile As String
Dim PauseTime As Long
Dim WordApp as New Word.Application
Dim item As Variant
Dim Start As Long
frmTreeview.cmdPrint.Enabled = False
' Add a new document to the documents collection
' Page Setup Section
WordApp.ActiveDocument.PageSetup.TopMargin = InchesToPoints(0.5)
WordApp.ActiveDocument.PageSetup.RightMargin = InchesToPoints(0.5)
WordApp.ActiveDocument.PageSetup.BottomMargin = InchesToPoints(0.5)
WordApp.ActiveDocument.PageSetup.LeftMargin = InchesToPoints(0.5)
WordApp.ActiveDocument.TrackRevisions = False
WordApp.ActiveDocument.ShowGrammaticalErrors = False
' Setup the Page Header
.Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Selection.Font.Name = "Times New Roman"
.Selection.Font.Size = "16"
.Selection.Font.Bold = True
.Selection = "Company Name"
.Selection = "Policies and Procedures"
For Each item In WordApp.Documents
Set WordApp = Nothing