Consulting

Results 1 to 6 of 6

Thread: Solved: running a jar file with arguments through VBA in Outlook

  1. #1
    VBAX Newbie
    Joined
    Apr 2008
    Location
    Dublin
    Posts
    4
    Location

    Question Solved: running a jar file with arguments through VBA in Outlook

    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.

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Just put the command switch after the file name. Ex:
    [VBA]objWSH.Run """C:\Documents and Settings\.......\myProgram.jar"" /foo"[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    VBAX Newbie
    Joined
    Apr 2008
    Location
    Dublin
    Posts
    4
    Location
    Thanks Oorang, works a charm

  4. #4
    VBAX Newbie
    Joined
    Apr 2008
    Location
    Dublin
    Posts
    4
    Location
    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

  5. #5
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Try this:
    [vba]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[/vba]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  6. #6
    VBAX Newbie
    Joined
    Apr 2008
    Location
    Dublin
    Posts
    4
    Location
    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 &
    [vba]

    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

    [/vba]
    Thanks again man. Problem solved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •