如何使用变量指示目录路径?

How to indicate a directory path using variables?

我要在VBA中实现某个.exe文件的使用。 .exe 将特定类型的文件作为输入并输出 .txt 文件。

当我写入输入和输出文件的整个目录时,代码有效。当我拆分目录并将部分存储在变量中时,它没有。

我需要拆分它,因为我要将这个 .exe 与不同的目录一起使用,以便用户可以选择想要的目录。

Sub convert()

    Dim directory As String
    Dim Filename As String

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

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

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

End Sub

您需要断开引号并连接以使用您的 file 字符串变量


Shell = "Hard_Coded_String_1" & file & "Hard_Coded_String_2"