Execute .bat File Within VBA

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.
 
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 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top