Shell command in VBA does not use PATH variable (execute .jar from VBA)

On Windows 7 (64-bit) and Office 2010, in a Word VBA macro, I make a call Shellfor java to execute a .jar file. The code is part of a distribution that supposedly works in Office 2007 (which I don't have).

ShellCommand = "java -classpath ..."
TaskID = Shell(ShellCommand, ShellWindowState)

In any case, the command Shellreturns the process identifier, but the process immediately exits without Err.Number. In fact, I can’t get a lot of information about why.

However, I suspected that I could not find the team java. I confirmed that my PATH is correct by manually opening a window CMD.exeand running ShellCommand(which I printed using Debug.Print). In fact, my PATH variable is configured to indicate where the last JRE is installed, which is also evidenced by input java -versionand viewing the correct output.

So, still not trusting Shellfrom VBA, I hard-coded ShellCommand as follows:

ShellCommand = "c:\Program Files\Java\jdk1.7.0_72\jre\bin\java -classpath ..."

In my (un) suprise, the Shell command works, and my .jar was executed as it should.

, , system PATH ShellCommand , , VBA, , JRE Windows 7 (java.exe - ), java.exe?

+4
1

TL; DR: Java 8

Java (!)

  • Java 7 72
  • Java 7 72 (64- )
  • Java SE Development Kit 7 72 (64- )
  • Java 8 25

PATH, Environ("PATH"), C:\ProgramData\Oracle\Java\javapath, SYMLINK :

C:\ProgramData\Oracle\Java\javapath>dir

 Directory of C:\ProgramData\Oracle\Java\javapath

2014-10-16  10:32    <DIR>          .
2014-10-16  10:32    <DIR>          ..
2014-10-16  10:32    <SYMLINK>      java.exe [C:\Program Files (x86)\Java\jre1.8.0_25\bin\java.exe]
2014-10-16  10:32    <SYMLINK>      javaw.exe [C:\Program Files (x86)\Java\jre1.8.0_25\bin\javaw.exe]
2014-10-16  10:32    <SYMLINK>      javaws.exe [C:\Program Files (x86)\Java\jre1.8.0_25\bin\javaws.exe]

Java 8.

javapath ( Java 7 64-):

C:\ProgramData\Oracle\Java\javapath>dir

 Directory of C:\ProgramData\Oracle\Java\javapath

2014-10-28  21:14    <DIR>          .
2014-10-28  21:14    <DIR>          ..
2014-10-28  21:14    <SYMLINK>      java.exe [C:\Program Files\Java\jre7\bin\java.exe]
2014-10-28  21:14    <SYMLINK>      javaw.exe [C:\Program Files\Java\jre7\bin\javaw.exe]
2014-10-28  21:14    <SYMLINK>      javaws.exe [C:\Program Files\Java\jre7\bin\javaws.exe]

VBA java.exe.

, PATH , .

, Java 8 (32-) Shell, .jar cmd.exe ( ).

+1

All Articles