Run batch files using Excel VBA

Martin1979

New Member
Joined
Mar 29, 2013
Messages
9
Hi all,

I was wondering if it is possible to run batch files using Excel VBA. I need to run multiple files using software from outside Excel.
However, to be efficient over the weekend, I would like to use Excel to open each file, run the file and after finishing, close it off and run the next file.
The idea is that the software (an executable) together with the files which need to run over the weekend, are in the same folder.
Does anyone know if this is possible? Hurdles are probably knowing when each file is finished and to close and open each file "*.otx" in the executable.
The executable has an GUI, which basically comes down to a button stating 'run'. However, to get there, the user needs to hit F9.

Any help is appreciated.

Regards,
Martijn
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Re: Help: Run batch files using Excel VBA

I was wondering if it is possible to run batch files using Excel VBA. I need to run multiple files using software from outside Excel.
However, to be efficient over the weekend, I would like to use Excel to open each file, run the file and after finishing, close it off and run the next file.
You could use Windows Script Host, like this:
Code:
    Dim batchFile As String
    Dim wsh As Object
    Set wsh = CreateObject("Wscript.Shell")
    batchFile = "C:\folder\path\commands.bat"
    wsh.Run """" & batchFile & """", 1, True '1 = show window; True = Wait for .bat to finish
    batchFile = "C:\folder\path\another.bat"
    wsh.Run """" & batchFile & """", 1, True
 
Last edited:
Upvote 0
Re: Help: Run batch files using Excel VBA

You could use Windows Script Host, like this:
Code:
    Dim batchFile As String
    Dim wsh As Object
    Set wsh = CreateObject("Wscript.Shell")
    batchFile = "C:\folder\path\commands.bat"
    wsh.Run """" & batchFile & """", 1, True '1 = show window; True = Wait for .bat to finish
    batchFile = "C:\folder\path\another.bat"
    wsh.Run """" & batchFile & """", 1, True

Thanks John_w,

But, how does it activates the 'run' button within the software?
Example: Software = Example.exe, F9 starts analysis within the software
Batch file 1: Test 1.otx
Batch file 2: Test 2.otx

Regards,
Martijn
 
Upvote 0
Re: Help: Run batch files using Excel VBA

To press a key (e.g. F9) you could try VBA SendKeys (in the VBA macro) or http://cpap.com.br/orlando/SendKeysMore.asp (in the VBA macro or the batch file). By 'batch file' I thought you meant a DOS batch file.

No, with batch files I mean multiple files in series. We call it batch files :). I will give it a try but if other people have good ideas about how to tackle this, I would like to know.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top