Solved

Word 97 Automation

Posted on 1998-10-08
5
181 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:sgroner
  • 3
5 Comments
 
LVL 1

Author Comment

by:sgroner
Comment Utility
Edited text of question
0
 
LVL 2

Expert Comment

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

Author Comment

by:sgroner
Comment Utility
Edited text of question
0
 
LVL 3

Accepted Solution

by:
fguerreiro_inix earned 100 total points
Comment Utility
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:sgroner
Comment Utility
Thanks for the tip.  It works fine now.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now