Running batch files (with spaces) from Excel

G

Guest

I am trying to run a .bat file from Excel. The Shell command works fine as long as there are no spaces in the path. So, for instance, running

C:\Apps\BFile.bat

works ok. But

C:\My Apps\BFile.bat

does not. The macro runs without an error, but the .bat file is simply not run.
Ideally, I would like to enter the path and file in a cell, and then click a button to run a macro to run the batch file. This means using double quotations

i = Shell (""C:\My Apps\BFile.bat"", 1)

would not be appropriate, as I am trying to use

Bat_File = Range("A2").Value
i = Shell (Bat_File, 1)

Anyone help?
 
J

jeff

HI,

If you paste C:\My Apps\BFile.bat into your cell A2 it
should work straight away. I pasted a bat file sitting
on my desktop ("C:\Documents and Settings\..") into
a cell, called the Shell as you do and it ran fine. No
quotes necessary.

jeff
-----Original Message-----
I am trying to run a .bat file from Excel. The Shell
command works fine as long as there are no spaces in the
path. So, for instance, running
C:\Apps\BFile.bat

works ok. But

C:\My Apps\BFile.bat

does not. The macro runs without an error, but the .bat file is simply not run.
Ideally, I would like to enter the path and file in a
cell, and then click a button to run a macro to run the
batch file. This means using double quotations
 

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

Top