Results 1 to 4 of 4

Thread: Automated instance of word waits for answer to question it never asks!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Location
    UK
    Posts
    4

    Question Automated instance of word waits for answer to question it never asks!

    I've created a program that uses automation through late-binding to word to open, edit and 'save as' documents. This is all done without the normal word user interface.

    Most of the time this works fine, but occasionally, word crashes while attempting to open the template document. My program then stalls, waiting for word to return, which it never does.

    I create the word object with the following code
    Code:
    If wdApp Is Nothing Then
        Set wdApp = CreateObject("Word.Application") 
    Else
        Set wdApp = GetObject(, "Word.Application")
    End If
    I open the template doc with

    Code:
    wdApp.documents.Open Config.AppPath & MasterBlankDoc
    MasterBlankDoc is a string containing the filename of the template document.

    Is there a way to enable my program to continue execution after calling the open instruction without waiting for wdApp to return control? And if so, is there a way to determine the state of word so my program can tell if it has crashed or not?

    Just to be really annoying, when word does crash, it leaves a file lock in memory on the template document, so when I re-run my program, as soon as it tries to open the doc again, word brings up a dialog box saying the doc is already open and can only be opened in read-only mode. However, this dialog box is always hidden in the background. The only way to get to it is to alt-tab, which is fine if you know about this, but to those users who don't, it just looks like the program has frozen up again!

    Any help or suggestions would be appreciated as this problem has been bugging me for months!

    Oh, for those who are interested, the program is used in a school to write and print student reports.

    Thanks.

    Ludwig.

  2. #2
    Frenzied Member TheBionicOrange's Avatar
    Join Date
    Apr 2001
    Location
    Cardiff, UK
    Posts
    1,818
    Do you have any error trapping in your routine ?

    If not I would advise some. In your error trap be sure to

    VB Code:
    1. set wdApp = nothing

    That will at least stop the lock on your template file.

    Why the template should sometimes crash I have no idea.

    HTH.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    An easy fix is to tell Word not to show dialogs, like this:

    wdApp.DisplayAlerts=False

    Be warned, this will mean that the Default action happens for dialogs that would be shown (which may cause issues for you). And you must remember to un-set this state at the end of your code (and in any error handlers), or Word will remember and not show messages when you want it to:

    wdApp.DisplayAlerts=True

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Location
    UK
    Posts
    4

    Talking

    Thanks for the suggestions guys.

    TheBionicOrange.

    I see what you're suggesting, catching the error after the call to the word function and handling it. However it never appears to my program that an error has actually occurred because execution never returns to my program. Even when single-stepping through the code, it gets to the word call and then waits for word to return. If word freezes, control is never returned and so my program, although not technically crashed, will wait indefinitely.

    What I need is a way to call a function provided by an OLE Automation object without waiting for it to return control. That way the error handling you suggested can then be invoked.

    si_the_geek.

    The word setting you suggest should solve the second part of my problem very well.


    Thanks again for your help guys.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width