none
Help Passing Arguments From VBA to .EXE RRS feed

  • Question

  • I'm trying to pass an argument from VBA to an executable file. I can do this with static values, but when trying to do it dynamically using a variable in the place of the static values, I have no luck. Would someone mind helping me out with this?

    VBA: Option Explicit Sub Main() Dim x As Variant Dim Path As String Dim File As String Dim MyValue As String MyValue = "Strawberries" '*** This passes properly: 'Path = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE ""Static value""" '*** This does NOT pass properly: Path = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE "MyValue"" File = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE" x = Shell(Path + " " + File, vbNormalFocus) End Sub

    ==========================================================================================================
    Executable File (C#.NET Application):

    namespace FindOutWhatKindOfFruit { class Program { static void Main(string[] args) { Console.WriteLine(args[0]); Console.ReadLine(); } } }

    I need to be able to pass variable values (dynamically) to the application from VBA but I can't seem to
    get it to allow variable passing.

    Monday, June 16, 2014 8:18 PM

Answers

  • Use:

    Path = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE """ & MyValue & """"

    or

    Path = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE " & Chr(34) & MyValue & Chr(34)

    Chr(34) is the double quote character ".


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, June 16, 2014 8:41 PM

All replies

  • Use:

    Path = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE """ & MyValue & """"

    or

    Path = "C:\Program Files (x86)\FindOutWhatKindOfFruit.EXE " & Chr(34) & MyValue & Chr(34)

    Chr(34) is the double quote character ".


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Monday, June 16, 2014 8:41 PM
  • That is great, that worked exactly the way I needed it to. Thank you!
    Monday, June 16, 2014 8:46 PM