Call .BAT file with paramaters using Excel

C

CraigKer

I want to call a .bat file with parameters using MS Excel. I tried both the
Shell command and Hyperlink but neither one will work when I try to pass
paramaters to the .bat file. For example if I use the following shell
command without parameters it works:

dim reset
reset = shell( "c:\reset-code.bat",1)

However, when I add my 4 parameters it does not work:
reset = shell("c:\reset-code.bat 2009 2008 Y:\account 19",1)

Has anyone run into this one?

Thanks in advance!!
 
B

Bernie Deitrick

This worked for me:

Sub RuntestProgram()
Dim program As String
program = "C:\Delete\test.bat fred"
TaskID = Shell(program)
End Sub


where test.bat was simply

copy C:\Delete\text.txt C:\Delete\%1.txt

It created the file fred.txt, a copy of text.txt
 
J

Jacob Skaria

Hi Craig

You code is fine.

Please check your .bat file for (4 parameters, path mentioned, file
extension mentioned etc; ) If you cannot find an issue paste your code and we
will have a look at it

If this post helps click Yes
 

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