Deckdyl
Deckdyl

Reputation: 103

How do i run a .exe file with file creation?

How do i program in excel VBA to run an external program with the external program being able to output the data collected into a file? My external program, voltage.exe, when run normally (double click the program on the desktop screen) will output the data collected into a file data.txt. However when run with my code below, the file data.txt was not being created.

Sub Button1_Click() ' run logger
Dim path As String
path = ActiveWorkbook.path
path = path + "\Voltage Recording.exe"
retval = Shell(path, vbNormalFocus)
End Sub

Upvotes: 0

Views: 1552

Answers (1)

houssam
houssam

Reputation: 1873

your file is created in the current directory, that you can get its path by function: CurDir() you can change the current directory by calling SetCurrentDirectory function:

Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Sub Button8_Click()
    MsgBox ("Old Dir = " & CurDir())
    SetCurrentDirectory ActiveWorkbook.path
    MsgBox ("Current Dir = " & CurDir())
    Dim path As String
    path = ActiveWorkbook.path

    path = path + "\Voltage Recording.exe"
    MsgBox (path)
    retval = Shell(path, vbNormalFocus)

End Sub

Upvotes: 2

Related Questions