Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    passing parameters to a batch file (XP)

    I am trying to use WinRAR to zip my backend MDBs (yes there are multiple) and I can't find any documentation on running WinRAR within VBA so I believe I need to use a batch file. So I need to pass the filename and zip destination to the batch file. I know how to use variables in batch files but I don't know how to pass these variables from VBA to the batch file. Unless you have a better alternative I have been using this code to call the batch file -

    Dim retval As Integer
    retval = Shell("Cirectorymy.bat", vbHide)

  2. #2
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: passing parameters to a batch file (XP)

    I can pass the parameters but not as variables

    retval = Shell("Cirectorymy.bat EchoThis1 Echothis2" , vbNormalFocus) works but this doesn't
    strOne = "Para 1"
    strTwo = "Para2"
    strZip = "C:0test.bat " & strOne & strTwo
    retval = Shell(strZip, vbNormalFocus)

    Where am I going wrong?

  3. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: passing parameters to a batch file (XP)

    I got it - I needed to put a space in front of the variables-
    strPara1 = " Para1"
    and you can't use spaces in the parameter.

    I Spent hours on this yesterday, but As soon as I post here I get the answer - Thanks Hans

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: passing parameters to a batch file (XP)

    If you need spaces in a parameter, put quotes around it:

    strOne = Chr(34) & "Para 1" & Chr(34)

  5. #5
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: passing parameters to a batch file (XP)

    good suggestion thanks Hans - I already found the need to surround parameters with quotes in the batch file even though you pass it as a string eg
    to replace "Cirectory" you need to use "%1"
    I guess all syntaxes are easy - given hindsight.

Posting Permissions

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