0

My first post in this great Q&A site, I hope somebody could help me.

Having a script in exe format that runs in DOS (script.exe). This script need a input file to process, so in DOS I need to do "Script.exe inputfile > ouputfile.txt".

It is possible to create a simple GUI in VBA with couple of buttons and inside the VBA application "insert" the script.exe?

It is possible to have the script.exe file inside the executable VBA GUI?

What I would like to achieve is have a GUI with a text asking for input file and a button to select the file to process and that the VBA app runs the script.exe.

1
  • 1
    VBA doesn't create a stand-alone applications. VBA only works inside Office package and doesn't create any executable files. You would need to download VS2012 Express for Desktop (free) and build a Windows Form application to achieve what you want. Commented Sep 26, 2013 at 7:51

1 Answer 1

1

You can't create standalone .exe files with VBA. You might be thinking of and not .

You have to make VBA programs in an Office application (generally Excel/Word/Access/Powerpoint/Outlook).

To do this:

  1. Create a userform with a submit button
  2. Name the submit button "cbSubmit"
  3. Add the following code to the code associated with the userform

    Private Sub cbSubmit_Click()
    
    Dim myCommand As String
    Dim myInputArg As String
    Dim myFile As Office.FileDialog
    Set myFile = Application.FileDialog(msoFileDialogFilePicker)
    
    With myFile
    
       .AllowMultiSelect = False
    
       ' Set the title of the dialog box.
       .Title = "Please select the file."
    
       ' Clear out the current filters, and add our own.
       .Filters.Clear
       .Filters.Add "All Files", "*.*"
    
       ' Show the dialog box. If the .Show method returns True, the
       ' user picked at least one file. If the .Show method returns
       ' False, the user clicked Cancel.
       If .Show = True Then
         myInputArg = .SelectedItems(1) 'replace txtFileName with your textbox
    
       End If
    End With
    
    'don't continue if user doesn't select something
    If myInputArg = "" Then Exit Sub
    'construct shell command
    myCommand = "Script.exe" & myInputArg & " > ouputfile.txt"
    
    'run shell command
    Dim returnVal As Double
    returnVal = Shell(myCommand, vbHide)
    
    End Sub
    
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the help. I'll try the code you share me. Once I'll be able to create the GUI interface and get working with the code, at the moment of the compilation of the VB program to make it executable, the the script.exe file will reside inside the exe program created by VBA? I mean script.exe will be part of the final .exe file generated by VBA? Or how can I do that, my goal is given a GUI to the script.exe program but having the final application in a single .exe. Thanks in again for the help.
@Zurix VBA doesn't generate executable files, so what you are suggesting will not work. I suggest researching VBA a bit more to clarify what you are asking.
Hello enderland, Well, with Visual Studio for example, I can convert a VBA project to executable? rigth? Maybe I've done incorrectly the question. I mean, how to include in a single exe program your VBA code and the script.exe? Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.