PDA

View Full Version : Solved: running a jar file with arguments through VBA in Outlook



kazuya
04-23-2008, 07:58 AM
Hi I'm a first time poster thats working on a project. My project calls an external Java program that sends off texts from the command prompt like:
java programName <argument>
I have seen how to call up the command prompt using shell scripts:


Private Sub CallApp()

Call Shell("C:\WINDOWS\system32\cmd.exe", 1)

End Sub

...and I have seen how to run a program:


Sub RunProgram()
Set objWSH = CreateObject("WScript.Shell")
objWSH.Run """C:\Documents and Settings\.......\myProgram.jar"""
End Sub

...but I can't find a way of putting extra arguments into the command line when I run the program. Is there a simpler way to just print a string to the command line and run it??

Any help would be greatly appreciated.

Oorang
04-23-2008, 08:46 AM
Just put the command switch after the file name. Ex:
objWSH.Run """C:\Documents and Settings\.......\myProgram.jar"" /foo"

kazuya
04-23-2008, 09:27 AM
Thanks Oorang, works a charm:)

kazuya
04-23-2008, 11:44 AM
That last solution works fine but now I'm geting some problems when I want to put a string defined in my VBA code into the argument for running the file.
My code calls a Java program that sends a text using arguments: a sender number, destination number and some text for the message.
It works fine if I want to send a preset text but I want to let my Outlook VBA application change the text based on different events.
The Jar file runs like any other program called in outlook:


Sub WebText()

Dim inputCommand As String
Dim textMessage As String

message = "hello"

Set objWSH = CreateObject("WScript.Shell")
objWSH.Run """F:\program folder\program.jar"" phonenumber1 phonenumber3 message"

End Sub
where phonenumber1 and phonenumber2 are numbers and message is the message. However this just sends a text message with "message" written in it so I was wondering if there were any escape characters available for me to put a pre defined variable in with these areguments?
thanks

Oorang
04-23-2008, 12:17 PM
Try this:
Sub Test()
WebText "F:\program folder\program.jar", "8008675309", "8005551212", "Don't forget these numbers."
End Sub

Sub WebText(programPath As String, ParamArray args() As Variant)
CreateObject("WScript.Shell").Run """ " & programPath & """" & Join(args, " ")
End Sub

kazuya
04-24-2008, 08:58 AM
Fantastic! I just had to change a couple of things but it worked. Heres the revised code. I just had to put triple quotes around the message part """Don't forget...""" and got rid of the gap in the 4 quotes before & programPart &


Sub Test()
WebText "F:\College\JSMS\jsms", "0876281660", "0876281660", """Don't forget these numbers."""
End Sub

Sub WebText(programPath As String, ParamArray args() As Variant)

CreateObject("WScript.Shell").Run """" & programPath & """" & Join(args, " ")

End Sub


Thanks again man. Problem solved.