Using Shell - Why it does not work for me?

actjfc

Active Member
Joined
Jun 28, 2003
Messages
416
Dear friends,

I have this VB code in a macro:

Sub BuildPRNFiles()
Dim RetVal

Start = Range("c5")
Finish = Range("c6")
'D9 contains the PATH

For x = Start To Finish

RetVal = Shell(Range("D9") & "r.bat" & " " & x, 1)

Delay = 3000
For y = 1 To Delay
Next y

Next x

End Sub

r.bat is a bacth file that runs a very old DOS program. r.bat runs just fine if I run it one at a time in DOS. However, if I want ot run it 1000 times using shell in Excel, it does not work. Excel is faster than this old DOS program. I tried the "delay" approach but it did not work always. The DOS program runs in a few seconds, but the delay works only sometimes not all times. So, excel runs the next one before the previous one has finished.

My question: How can I modify this code to be certain that each time I run r.bat, Excel will certainly run the next file or program on the loop only when the previous one has finished running in DOS?

Thanks to all the good people out there!!!!!!! :biggrin:
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,202,977
Messages
6,052,888
Members
444,608
Latest member
Krunal_Shah

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