send parameters to a batch file with the shell command

M

Marcos

Hi,
I've tried succesfully to call a batch macro from excel with the shell
command.
But when I add parameters to the shell pathname it does not work.

assume the batch file x.bat content is:
echo year is %1
pause

The following works well:
Dim RetVal
mycmd = "C:\temp\x.bat"
RetVal = Shell(mycmd, 1)

but:
Dim RetVal
mycmd = "C:\temp\x.bat 2006"
RetVal = Shell(mycmd, 1)

does not work.

Any help will be appreciated
Marcos
 
A

Ardus Petus

Dim RetVal
mycmd = "C:\temp\x.bat 2006"
RetVal = Shell(mycmd, 1)

works by me!

x.bat contains 1 line:
echo %1
 
M

Marcos

Ardus
Thanks, it did work for me as well...
My real problem was calling a macro in the directory C:\Documents and
Settings\Marcos\Desktop\temp.
For the email i wrote c:\temp to simplify, but and as I tried with
c:\temp it did work as you said.

This helped me workout the solution. I was running
mycmd= "C:\Documents and Settings\Marcos\Desktop\temp\x.bat 2006"
RetVal = Shell(mycmd, 1)
it seems a double quetes were needed for the path above.
Adding:
mycmd= chr$(34)+"C:\Documents and
Settings\Marcos\Desktop\temp\x.bat"+chr$(34)+" 2006"
did the trick.
thanks for the help,
Marcos
 
A

Ardus Petus

You could have written:
mycmd= ""C:\Documents and Settings\Marcos\Desktop\temp\x.bat"" 2006"

HTH
 
T

Tom Ogilvy

maybe one more "

mycmd= """C:\Documents and Settings\Marcos\Desktop\temp\x.bat"" 2006"
? mycmd
"C:\Documents and Settings\Marcos\Desktop\temp\x.bat" 2006
 
A

Ardus Petus

Sure!

--
AP

Tom Ogilvy said:
maybe one more "

mycmd= """C:\Documents and Settings\Marcos\Desktop\temp\x.bat"" 2006"
? mycmd
"C:\Documents and Settings\Marcos\Desktop\temp\x.bat" 2006
 

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