Solved

Word 97 Automation

Posted on 1998-10-08
5
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

688 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