Execute .bat File Within VBA

  • Thread starter Thread starter Jonas
  • Start date Start date
J

Jonas

I have a batch file that is created via VBA. I have tried using the
Shell command to get it to execute but it will only execute in this
way if I put the shell command in the immediate window. the batch
file will also execute if I double click on it. Do you have any
suggestions as to what I might be doing wrong?

I have tried: Shell ("c:\batchfile.bat")

and:

strShell = "CMD.EXE /c c:\batchfile.bat"
Call Shell(strShell, vbMaximizedFocus)

Neither have worked.
 
I have a batch file that is created via VBA.  I have tried using the
Shell command to get it to execute but it will only execute in this
way if I put the shell command in the immediate window.  the batch
file will also execute if I double click on it.  Do you have any
suggestions as to what I might be doing wrong?

I have tried: Shell ("c:\batchfile.bat")

and:

strShell = "CMD.EXE /c c:\batchfile.bat"
Call Shell(strShell, vbMaximizedFocus)

Neither have worked.

I put in a couple of "pause" commands and I was able to find the
problem. When running a batch file from VBA, the default directory is
used. I had to specify that I was working on the C:\ drive when I
renamed my file.
 
Back
Top