Solved

Word 97 Automation

Posted on 1998-10-08
5
186 Views
Last Modified: 2010-04-30
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
    WordApp.Documents.Add
   
    With WordApp.ActiveWindow

        ' 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.Collapse Direction:=wdCollapseEnd
        .Selection.TypeParagraph
        .Selection = "Policies and Procedures"
        .Selection.Collapse Direction:=wdCollapseEnd
        .Selection.TypeParagraph
        .Selection.TypeParagraph

    End With
   
    For Each item In WordApp.Documents
        Debug.Print item.Name
        item.Close wdDoNotSaveChanges
    Next
   
    WordApp.Quit

    Set WordApp = Nothing
0
Comment
Question by:Steve Groner
  • 3
5 Comments
 
LVL 1

Author Comment

by:Steve Groner
ID: 1438957
Edited text of question
0
 
LVL 2

Expert Comment

by:mkmccreary
ID: 1438958
A copy of the code calling Word would be nice.
0
 
LVL 1

Author Comment

by:Steve Groner
ID: 1438959
Edited text of question
0
 
LVL 3

Accepted Solution

by:
fguerreiro_inix earned 100 total points
ID: 1438960
Instead of use early binding, use late binding and GetObject and CreateObject.

Some time ago I have a problem like that and I solve this way.


Dim wordApp as object

'--- You need to put this error handling
on error resume next

set wordApp = createObject(Word.application)

If Err.Number <> 0 Then
    Set wordApp = GetObject(, Word.application)
    err=0
End If

----------------------------------------
If this doesn't work change the order of use of GetObjects and CreateObjects functions.


Hope this helps
Regards
0
 
LVL 1

Author Comment

by:Steve Groner
ID: 1438961
Thanks for the tip.  It works fine now.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question