问题
In an MS Access public function, I run a java xslt module using a shell call:
Set shell = CreateObject("WScript.Shell")
cmd = "java -jar D:\saxon9he.jar -s:D:\input.xml -xsl:D:\transf.xslt -o:D:\output.xml"
Set objExecObject = shell.Exec(cmd)
I caught the following error:

As exactly the same worked fine in another MS Access instance, I assume I have to refer to an environment variable somewhere (one of these is JAVA_HOME
which has been set to C:\Program Files\Java\jdk1.5.0_16\bin
).
But where in MS Access can I set that reference?
Or is this error caused by something else?
Might there for instance be trouble with MS Access / VBA accessing the environment variable PATH
in USER
and/or SYSTEM
? In my setup, it's the user environment paramater PATH
that holds the information on the location of java.exe.
回答1:
I added stuff to the command to be executed as follows:
Set shell = CreateObject("WScript.Shell")
Dim JavaHome As String
JavaHome = shell.Environment("USER")("JAVA_HOME") & "\"
cmd = JavaHome & "java -jar D:\saxon9he.jar -s:D:\input.xml -xsl:D:\transf.xslt -o:D:\output.xml"
Set objExecObject = shell.Exec(cmd)
This works fine, as I now supply the path to java.exe myself.
But I still wonder, why all of a sudden MSA/VBA could not apply the PATH
parameter from user environment (which includes ;%JAVA_HOME%;) any more...
I will create another thread for that question...
来源:https://stackoverflow.com/questions/10879757/vba-shell-java-call-errors