Results 1 to 2 of 2
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Yilgarn region of Toronto, Ontario
    Thanked 0 Times in 0 Posts

    Terminate a SHELLed task? (office97)

    Is there a <font color=red>simple</font color=red> way to terminate a SHELLed task? (Simple as in "not getting into complex API calls"). The VBA Help is great at launching task, and obtaining the RetVal, but gives no hint as to how to rein in an unleashed beast.

    The code below shells out to a browser and pulls up a web page. I want to gaze (in silent admiration!) at the web page (but it could be a Word document or an Email message ...) for a moment, and have the VBA code terminate the task and move on to the next page.

    <pre>Sub test()

    Dim strWebPlaces As String
    strWebPlaces = "C:GreavesAdminWeb2Go"
    Dim strFile As String
    strFile = Dir(strWebPlaces & "*.htm*")
    Dim strDestination As String
    strDestination = "" & strFile

    While strFile <> ""
    Dim retval As Long
    retval = Shell("C:Program FilesMozilla Firefoxfirefox.exe " & strDestination)
    '????? In here, pause for two seconds, then terminate the Browser program??????
    strFile = Dir

    End Sub</pre>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Sacramento, California, USA
    Thanked 1 Time in 1 Post

    Re: Terminate a SHELLed task? (office97)

    You can use the ProcessID returned by the Shell command to activate the application and then use SendKeys to send an Alt+F4 to close the window.

    AppActivate RetVal
    SendKeys "%{F4}"

Posting Permissions

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