+ Reply to Thread
Results 1 to 8 of 8

Open one command window and execute a series of commands from it.

  1. #1
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Question Open one command window and execute a series of commands from it.

    I would like to open a command window/prompt (e.g. cmd.exe) and pass a single line command to it, wait for it to finish, and pass another command to it, continuing until done and then close the command window.

    Thinking about this, I guess I could build a multi-line command list and pass that to the command window and let it execute, continuing with the VBA once the commands are done executing. However, I would prefer my opening request because it would show how it can actually be done (reuse an open window).

    I've found a few things where a single command is run and the window is then closed but it doesn't get reused:
    http://www.pcreview.co.uk/forums/run...-t3895036.html
    http://support.microsoft.com/kb/129797

    I don't know if these are the right track for me or not. I've never had a need to run the command window and execute multiple command from inside Excel so this is a new learning opportunity for me.
    Last edited by Air_Cooled_Nut; 12-17-2013 at 06:29 PM. Reason: Solved.
    ~Toby

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Open one command window and execute a series of commands from it.

    From:
    http://stackoverflow.com/questions/1...nd-to-complete
    Please Login or Register  to view this content.
    Where "C:\folder\runbat.bat" is what you want to pass to the command window. That should wait for it to finish before continuing the vba code.

  3. #3
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: Open one command window and execute a series of commands from it.

    I don't want to run a batch file, I want to pass commands to the command window on the fly. The command window is to remain open, accepting new commands as they come, and only close once I command it to.

  4. #4
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Open one command window and execute a series of commands from it.

    Well you could do something like:
    Please Login or Register  to view this content.
    and repeat.

  5. #5
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: Open one command window and execute a series of commands from it.

    From what I've tried to find it looks like what I want isn't possible. yudlugar, I was thinking the same idea. Well, good to have a second opinion that confirms what I was thinking, thanks for your input. Looks like I'll be using that route.

  6. #6
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Open one command window and execute a series of commands from it.

    As far as I'm aware you need to use Wscript to get the waitonreturn option.

  7. #7
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: Open one command window and execute a series of commands from it.

    I think I'll be incorporating this --> http://support.microsoft.com/kb/129796/EN-US
    to 'pause' VBA processing.

  8. #8
    Registered User
    Join Date
    10-26-2004
    Location
    Portland, Oregon
    MS-Off Ver
    Excel in Windows
    Posts
    49

    Re: Open one command window and execute a series of commands from it.

    Here's my work-around.
    Please Login or Register  to view this content.
    The function used to run the batch script:
    Please Login or Register  to view this content.
    For my purposes the batch file is created in the same location as the Excel workbook. Just makes things easier. Due to the EXIT command in my batch script the return value will be zero; this is why I don't care about the function's return value.

    What's nice about this is that the VBA code will stop executing until the batch script is done (waitOnReturn:=True). Thus the need to close the cmd window using the /c switch (Command:="%comspec% /c "). I ensure this by also using the EXIT command.

    HTH.
    Last edited by Air_Cooled_Nut; 01-03-2014 at 11:53 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to send multiple commands to an already open cmd window?
    By Marksman1973 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2013, 08:26 AM
  2. VBA code to open and execute files from different directories in Command window
    By AlexXYZ in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2012, 01:49 PM
  3. VBA code to open and execute files from different directories in Commend window
    By AlexXYZ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2012, 01:52 AM
  4. Command line for open excel, insert a sheet, execute a macro, save file exit?
    By uschxc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2012, 12:28 PM
  5. command button to open a window
    By slmi1313 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2008, 12:38 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1