Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Shell / Wait (Word 2003)

    I'm not having good luck executing a Shell command which I want to finish before my code continues. I've searched here and elsewhere and nearly ever code sample has a problem. I want to run this at the beginning of my code, so there is no user form involved. The EXE retireves data from a database, and displays a progress bar so the user is aware of activity.

    The code below seemed to be the most straightforward that I found. An error occurs as I've indicated below. The error is: Runtime error 53; File not found: Kernal.

    Perhaps this is obsolete code. I'd prefer to keep this simple; some of the examples I found had dozens of declarations.

    Thanks,
    Richard


    Private Declare Function GetModuleUsage% Lib "Kernel" _
    (ByVal hModule%)

    Private Function TestFunc(ByVal lVal As Long) As Integer
    'this function is necessary since the value returned by Shell is an
    'unsigned integer and may exceed the limits of a VB integer
    If (lVal And &H8000&) = 0 Then
    TestFunc = lVal And &HFFFF&
    Else
    TestFunc = &H8000 Or (lVal And &H7FFF&)
    End If
    End Function


    Sub TestWithNotepad()
    Dim lret&
    Dim x%, z%
    lret& = Shell("NOTEPAD.EXE")
    x% = TestFunc(lret&)
    While GetModuleUsage(x%) > 0 ' Has Shelled program finished? ' *** ERROR OCCURS HERE
    z% = DoEvents() ' If not, yield to Windows.
    Wend
    MsgBox "Shelled application just terminated", 64
    End Sub

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

    Re: Shell / Wait (Word 2003)

    GetModuleUsage was a Windows 3.x API function. It hasn't been available since Windows 95 / Windows NT4.

    You can use the WaitForSingleProcess API function - see for example How To Use a 32-Bit Application to Determine When a Shelled Process Ends.

  3. #3
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    New York, NY
    Posts
    922
    Thanks
    2
    Thanked 12 Times in 11 Posts

    Re: Shell / Wait (Word 2003)

    Thanks very much. I tried a similar version to this linked code (for the Windows Calculator) and it didn't work. The code at the link you've sent works perfectly.

    Regards,
    Richard

Posting Permissions

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