Running a .bat file with spaces in the path.

G

Guest

I am trying to run a .bat file from a macro. The shell command works okay most of the time - but I cannot seem to make it work if there is a space in the path. (So, running C:\Apps\BFIle.bat works, but not C:\My Apps\BFile.bat)

As the .bat file I want to run will change, I want to enter the path in a cell, and then run the macro with a button. This means simply enteing the path in double quotation marks in the Shell command will not work.

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

Any ideas?
 
J

Jim Rech

Odd that a space is giving you a problem. This works for me whether the
path has a space or not:

Shell Range("A1") & "\123.bat"

--
Jim Rech
Excel MVP
|I am trying to run a .bat file from a macro. The shell command works okay
most of the time - but I cannot seem to make it work if there is a space in
the path. (So, running C:\Apps\BFIle.bat works, but not C:\My
Apps\BFile.bat)
|
| As the .bat file I want to run will change, I want to enter the path in a
cell, and then run the macro with a button. This means simply enteing the
path in double quotation marks in the Shell command will not work.
|
| BFile = Range("A2").Value
| i = Shell (BFile, 1)
|
| Any ideas?
 

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