使用VBA从Excel运行bat文件

时间:2016-06-20 10:05:24

标签: vba excel-vba batch-file batch-processing excel

我的 test.bat 文件包含脚本:

<tr ng-repeat="person in people| filter: {age>20}" >

通常当我点击它时,它工作正常。现在,我想使用vba从Excel运行test.bat文件。

copy host_name table_name -p table_name -t "file.csv"
有些东西是错的,因为我只看到了快照/剪辑:就像有些东西是开放的,接近一秒......

2 个答案:

答案 0 :(得分:4)

刚刚解决了它:

ChDir ThisWorkbook.Path & "\folder\"
Shell ThisWorkbook.Path & "\folder\test.bat", vbNormalFocus

答案 1 :(得分:0)

我不确定您使用的是VBA和shell,但尝试类似这样的

Dim winShell As Object: Set winShell = CreateObject("WScript.Shell")

    Dim WaitOnReturn As Boolean: WaitOnReturn = False
    Dim windowStyle As Integer: windowStyle = 1

    'Run the desired pair of shell commands in command prompt.
    Call winShell.Run("cmd /k " & command1 & " & " & command2, windowStyle, WaitOnReturn)

    'Release pointer to the command prompt.
    Set winShell = Nothing

只需用你的命令替换我的命令,然后看看它是否有效

编辑:只是为了完成我的命令看起来像这个

Dim command1 As String: command1 = "cd /d" & projectDirectoryCell.Value

Dim command2 As String: command2 = "create_sensi.bat"