【问题标题】:How to indicate a directory path using variables?如何使用变量指示目录路径?
【发布时间】:2020-06-12 18:19:29
【问题描述】:

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

当我编写输入和输出文件的整个目录时,代码可以工作。当我拆分目录并将部分存储在变量中时,它不会。

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

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

【问题讨论】:

  • 你把它全部放在引号里,所以它只是读取文字字符串“文件”而不是你分配的变量。

标签: vba shell path command executable


【解决方案1】:

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


Shell = "Hard_Coded_String_1" & file & "Hard_Coded_String_2"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-07
    • 2018-07-28
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2020-01-03
    相关资源
    最近更新 更多