1

so I'm trying to get a very simple shell command to execute a batch file that's created, but for some reason the shell command doesn't do anything.

The batch file gets created and when I double click on the batch file it executes the script just fine, but if I try to call the shell command in VBA it appears that it tries to open a command window, but immediately closes it after, not producing any errors. This code used to work fine before I reformatted this laptop AND this code works on another system running Server 2012 R2 (I'm running windows 10)

        Dim SedjaShell
        f = "C:\Temp\_SedjaScript.bat"
        Open f For Output As #1
        Print #1, Chr(34) & SedjaDir & Chr(34) & " merge --files " & Page1 & " " & Page2 & " " & TOS & " " & Disclosure & " --output " & OutputDir
        Print #1, "Pause"
        Close #1

        SedjaShell = Shell("C:\Temp\_SedjaScript.bat", 1)

Is there something I might be missing?

EDIT Adding the contents of _SedjaScript.Bat

"C:\Users\User\Desktop\DealTracker\MergeFiles\sejda-console-3.0.4\bin\sejda-console.bat" merge --files C:\Temp\ContractSummary.pdf C:\Temp\Page2.pdf C:\Temp\TOS.pdf C:\Temp\Disclosure.pdf --output "C:\Users\User\Desktop\DealTracker\Completed Contracts\Company-Name-Inc-07-19-2017-Contract.pdf"
Pause
9
  • Are you sure it's not working? It could have done its thing and closed itself, as that's the default behavior of a batch script. Commented Jul 19, 2017 at 20:53
  • I know it's not working since the output file doesn't exist. I also just tried this exact same code on another system and it worked just fine. Also if it was working the script window would remain up since I added a pause condition at the end of the script. However if I manually launch the .bat file the script launches and outputs the merged file Commented Jul 19, 2017 at 20:54
  • Your batch file might be using relative paths. Try changing the working directory for the Shell command using ChDir (and ChDrive if required). If I had to guess, you'd want to do ChDir "C:\Temp". Commented Jul 19, 2017 at 20:56
  • Nope that didn't work Commented Jul 19, 2017 at 21:07
  • Try displaying (Debug.Print or MsgBox) exactly what you're writing to the batch file. Commented Jul 19, 2017 at 21:28

1 Answer 1

1

Thanks to Andre I was able to get the script to work inside VBA's Shell command.

By setting the PATH for my JRE to JAVA_HOME I was able to successfully launch the script.

setx JAVA_HOME "C:\Program Files (x86)\Java\jre1.8.0_141"
setx PATH "%PATH%;%JAVA_HOME%\bin";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.