+ Reply to Thread
Results 1 to 7 of 7

send parameters to a batch file with the shell command

  1. #1
    Marcos
    Guest

    send parameters to a batch file with the shell command

    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


  2. #2
    Ardus Petus
    Guest

    Re: send parameters to a batch file with the shell command

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

    works by me!

    x.bat contains 1 line:
    echo %1

    --
    AP

    "Marcos" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > 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
    >




  3. #3
    Marcos
    Guest

    Re: send parameters to a batch file with the shell command

    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


  4. #4
    Ardus Petus
    Guest

    Re: send parameters to a batch file with the shell command

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

    HTH
    --
    AP

    "Marcos" <[email protected]> a écrit dans le message de news:
    [email protected]...
    > 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
    >




  5. #5
    Tom Ogilvy
    Guest

    Re: send parameters to a batch file with the shell command

    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

    --
    Regards,
    Tom Ogilvy

    "Ardus Petus" <[email protected]> wrote in message
    news:[email protected]...
    > You could have written:
    > mycmd= ""C:\Documents and Settings\Marcos\Desktop\temp\x.bat"" 2006"
    >
    > HTH
    > --
    > AP
    >
    > "Marcos" <[email protected]> a écrit dans le message de news:
    > [email protected]...
    > > 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
    > >

    >
    >




  6. #6
    Ardus Petus
    Guest

    Re: send parameters to a batch file with the shell command

    Sure!

    --
    AP

    "Tom Ogilvy" <[email protected]> a écrit dans le message de news:
    %[email protected]...
    > 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
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    > "Ardus Petus" <[email protected]> wrote in message
    > news:[email protected]...
    >> You could have written:
    >> mycmd= ""C:\Documents and Settings\Marcos\Desktop\temp\x.bat"" 2006"
    >>
    >> HTH
    >> --
    >> AP
    >>
    >> "Marcos" <[email protected]> a écrit dans le message de news:
    >> [email protected]...
    >> > 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
    >> >

    >>
    >>

    >
    >




  7. #7
    Marcos
    Guest

    Re: send parameters to a batch file with the shell command

    Thanks to all
    it's much easier the way you say


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1