Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run method in script (.VBS/ Word2000)

    <P ID="edit" class=small>(Edited by AlanMiller on 24-Mar-05 10:02. Kludged, but why?)</P>I've encountered an odd problem when running winword/ opening a Word document from a VBS script. I use the Run method as follows:

    Set WshShell = WScript.CreateObject("WScript.Shell")
    Return = WshShell.Run("E:My DocumentsSurvey.doc", 1)

    Word opens as normal and the script finishes, but when I try to close Word it hangs and must be terminated from Ctrl+Alt+Del. I'm sure this is not a problem with Word itself, but something to do with the Run method. It doesn't happen when Excel or a .XLS file is opened by similar means, and winword.exe closes normally if opened by the usual means. Using the alternative (but undesirable DOS box) Exec method from a script also works without a hitch:

    cmdLine = "Start " + chr(34) + "E:My DocumentsSurvey.doc" + chr(34)
    WshShell.Exec(cmdLine)

    Any ideas/ solutions appreciated.

    Alan

    Edited - I find that if the last line of the script is an innocuous command, like: msgbox "Script ended"
    then the problem doesn't arise. I still don't understand the reason. <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Run method in script (.VBS/ Word2000)

    I'm not sure whether there is an advantage to using the Shell in this case. Could you use Word automation?

    Dim appWord
    Set appWord = WScript.CreateObject("Word.Application")
    appWord.Visible = True
    appWord.Documents.Open "E:My DocumentsSurvey.doc"
    Set appWord = Nothing

    I guess if some other application is supposed to handle .DOC files, then this would not work for your needs.

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run method in script (.VBS/ Word2000)

    Hi Jefferson

    I just isolated this part of the code as the problem. The script actually loops through an array of these string "command lines", running each one. So there might be a mixture of all types of file associations. For that reason, automation would not be suitable, or even applicable. There are no problems that I've seen in launching non-Word files either.

    Still stumped on why Word seems to be the only misbehaving app, and why "closing out" the script with a command like "msgbox" seems to solve the problem ???

    cheers
    Alan

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Run method in script (.VBS/ Word2000)

    Building in a small delay instead of a message box would probably prevent the problem too. See this newsgroup thread.

  5. #5
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run method in script (.VBS/ Word2000)

    Good find Hans. "WScript.Sleep 2000" did the trick.

    cheers
    Alan

Posting Permissions

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