Directory names when using the Shell() function

G

Guest

I'm trying to use the Shell() function to run a .JAR file that does some
calculations for the database I'm working on. For some reason if I put the
..JAR file in a folder that contains a space in the folder name, I get the
error message "Invalid procedure call or argument". Here's the code that I'm
using:

Private Sub Command0_Click()
Dim retval
retval = Shell("java -jar " & "C:\adherence\Adherence
Schedule\CalculatorBatch_v2.jar", vbNormalFocus)
End Sub

The above is prodcucing the error message I described. The below code works:

retval = Shell("java -jar " & "C:\adherence\CalculatorBatch_v2.jar",
vbNormalFocus)

I moved the .JAR file up a directory to a folder that doesn't contain any
spaces in the folder name. Any ideas why the Shell() function doesn't like
spaces in the folder name? Thanks.
 
D

Dirk Goldgar

In
pareez said:
I'm trying to use the Shell() function to run a .JAR file that does
some calculations for the database I'm working on. For some reason
if I put the .JAR file in a folder that contains a space in the
folder name, I get the error message "Invalid procedure call or
argument". Here's the code that I'm using:

Private Sub Command0_Click()
Dim retval
retval = Shell("java -jar " & "C:\adherence\Adherence
Schedule\CalculatorBatch_v2.jar", vbNormalFocus)
End Sub

The above is prodcucing the error message I described. The below
code works:

retval = Shell("java -jar " & "C:\adherence\CalculatorBatch_v2.jar",
vbNormalFocus)

I moved the .JAR file up a directory to a folder that doesn't contain
any spaces in the folder name. Any ideas why the Shell() function
doesn't like spaces in the folder name? Thanks.

Presumably it's parsing the command line based on space delimiters.
That's common. Try embedding quotes around your file name:

Dim strFileName As String

strFileName = "C:\adherence\Adherence
Schedule\CalculatorBatch_v2.jar"

retval = Shell("java -jar " & Chr(34) & strFileName & Chr(34), _
vbNormalFocus)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top