Solved

Word 97 Automation

Posted on 1998-10-08
5
185 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

840 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