Error Executing cmd File

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,163
when I use this code to try to execute my cmd file:

Code:
 Call Shell(Environ$("COMSPEC") & " /k " & "Q:\IRP11\COS_LRFF\RTSim Files\Output\RTSimWriteOut.cmd", vbNormalFocus)

I get this msg in the prompt: "Q:\IRP11\COS_LRFF\RTSim' is not recognized as an internal or external command, operable program or batch file."

What gives??
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
There's a space in the program folder path, so you need to surround it with quotes:
Code:
Call Shell(Environ$("COMSPEC") & " /k " & Chr(34) & "Q:\IRP11\COS_LRFF\RTSim Files\Output\RTSimWriteOut.cmd" & Chr(34), vbNormalFocus)
 
Upvote 0
I just tried it and it still didn't work, now the window pops up and disappears almost immediately.
 
Upvote 0
I don't know. Try the Q:\IRP11\COS_LRFF\RTSim Files\Output\RTSimWriteOut.cmd manually. Does a simple DIR command work? Like this:
Code:
    Shell Environ$("COMSPEC") & " /k " & "dir " & Chr(34) & "C:\Program Files\" & Chr(34), vbNormalFocus
 
Upvote 0
Yes the dir action worked...Do you think it might be the cmd file itself? Here is what is in the cmd file:
Code:
FOR %%f IN (*.o_g) DO CALL C:\RTSimEXE\RTOutput.exe %cd%\%%f Month
FOR %%f IN (*_Mon.csv) DO REN "%%f" "%%~nf_%date:~4,2%%date:~7,2%%date:~10,4%%%~xf"
SETLOCAL enabledelayedexpansion
SET deletestring=_Mon
FOR /f "delims==" %%F IN ('dir /b *.csv ^| FIND "%deletestring%"') DO (
     SET oldfilename=%%F 
     SET newfilename=!oldfilename:%deletestring%=! 
     REN "!oldfilename!" "!newfilename!"
     )
EXIT

In a nutshell the cmd loops through all .o_g files in the current directory (directory it resides in) and calls an .exe. The .exe creates .csv files with an "_Mon" in the name, this cmd file will replace the "_Mon" with today's date. The cmd file works great when I double click it, but it won't work when I try to run it from the vba code we've been talking about.
 
Upvote 0
Do you think it might be the cmd file itself?
You can determine that by running it yourself from a command window. Does it work from any directory, or only when you run it from Q:\IRP11\COS_LRFF\RTSim Files\Output\?

In a nutshell the cmd loops through all .o_g files in the current directory (directory it resides in)
That might be the problem when it is run from Excel. Pay attention to the current directory when you run it from Excel; to determine this, add the following 2 lines to the top of the .cmd file:

chdir
pause

The chdir command without an argument displays the current directory. You might need to change the current directory to the correct directory, either in the .cmd file itself with chdir C:\this\directory\ or in VBA with the ChDir statement.
 
Upvote 0
You're right!! adding "ChDIR C:\this\directory\" to the top of the cmd file worked!!

Thankyou very much for your time and help.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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