Results 1 to 3 of 3

Thread: Wait for Shell command to finish in VBA Excell?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    20

    Wait for Shell command to finish in VBA Excell?

    I'm using I have an external .exe which I start with the shell command. The .exe in question is just a homebrew form, looks like it could have been written with VB itself. It has a few spaces for data entry and once the proper data has been filled in, you use a dialogue box to select a file and the tool converts the file to a different format. This external application that I'm controlling starts a new MSDOS process to some "conversion" of files. For some reason (at least so far) when I run it through the shell command the MSDOS process dies. I can't see how or why it's failing, but it doesn't do what it's supposed to do. If I run the program manually I can get it to work every time. Any ideas?

    I've been trying to try using the WaitForSingleObject API to wait until everything is done and see if that fixes it, but I'm not having much luck. The code I've found online doesn't seem to work with VBA exactly and I haven't been able to figure out how to tweak it.

    Also I think the key might be that I need the process ID for the MSDOS task, I have obtained the handle for the window that comes up, but I don't think it's the same and I don't know how to proceed. Any ideas, helpful suggestions?

    Thanks,
    Matt

  2. #2
    Lively Member
    Join Date
    Jun 2005
    Posts
    112

    Re: Wait for Shell command to finish in VBA Excell?

    VB Code:
    1. Set Sh = CreateObject("WScript.Shell")
    2. cmd = "c:\yourApp.exe"
    3. ReturnCode = Sh.Run(cmd, 1, True)

    Processing will wait for shell to finish.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    20

    Re: Wait for Shell command to finish in VBA Excell?

    Mike,

    The code isn't working for me. I get the following error message :

    Run-time error '02147024894 (80070002)';
    Method 'Run' of object 'IWshShell2' failed

    Any other hints? I've been trying to use WaitForSingleObject as I mentioned below, but without much luck. I think I might not be obtaining the process handle correctly, but the method shown in the code I have access to does not seem to work in VBA.

    Thanks,
    Matt

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