How to indicate a directory path using variables?

Viewed 57

I have to implement the use of a certain .exe file in VBA. The .exe takes as input a specific type of file and outputs a .txt file.

When I write the whole directory of both the input and output files, the code works. When I split the directory and store the parts in variables, it doesn't.

I need to split it because I am going to use this .exe with different directories so the user could choose the wanted directory.

Sub convert()

    Dim directory As String
    Dim Filename As String

    directory = "C:\Users\user1\Desktop\reporting\201703161224"
    Filename = "\input.set"

    Shell "cmd /c""C:\Users\user1\Desktop\reporting\appli.exe 
    C:\Users\user1\Desktop\reporting\201703161224\input.set> 
    C:\Users\user1\Desktop\reporting\201703161224\output.txt"
    'this works well

    file = directory & Filename
    Shell "cmd /c""C:\Users\user1\Desktop\reporting\appli.exe file>
    C:\Users\user1\Desktop\reporting\201703161224\output.txt"
    'this doesn't work

End Sub
1 Answers

You need to break out of the quotes and Concatenate to use your file string variable


Shell = "Hard_Coded_String_1" & file & "Hard_Coded_String_2"
Related