[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Word 97 Automation

Posted on 1998-10-08
5
Medium Priority
?
193 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 400 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

Industry Leaders: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

649 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