Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA宏不执行.bat文件_Vba_Excel - Fatal编程技术网

VBA宏不执行.bat文件

VBA宏不执行.bat文件,vba,excel,Vba,Excel,批处理文件可以手动执行,但当我尝试从Excel中的宏执行时,在调用Shell(stAppName,1)行上会出现“运行时错误'5'无效过程调用或参数”。这是我的密码: Private Sub run_Click() Const DELIMITER As String = "," 'or "|", vbTab, etc. Dim myRecord As Range Dim myField As Range Dim nFileNum As Long Dim s

批处理文件可以手动执行,但当我尝试从Excel中的宏执行时,在
调用Shell(stAppName,1)
行上会出现“运行时错误'5'无效过程调用或参数”。这是我的密码:

Private Sub run_Click()
    Const DELIMITER As String = "," 'or "|", vbTab, etc.
    Dim myRecord As Range
    Dim myField As Range
    Dim nFileNum As Long
    Dim sOut As String

    nFileNum = FreeFile
    Open "C:\apps\Test.bat" For Output As #nFileNum
    For Each myRecord In Range("B20:B24")
        With myRecord
            For Each myField In Range(.Cells(1), _
                    Cells(.Row, Columns.Count).End(xlToLeft))
                sOut = sOut & DELIMITER & myField.Text
            Next myField
            Print #nFileNum, Mid(sOut, 2)
            sOut = Empty
        End With
    Next myRecord
    Close #nFileNum

Dim stAppName As String

stAppName = "cmd.exe /k c:\apps\test.bat"
Call Shell(stAppName, 1)

End Sub

你试过换衣服吗

stAppName = "cmd.exe /k c:\apps\test.bat"


你应该以文本形式发布你的代码。请不要发布代码的截图。相反,将代码复制到问题中,并将其格式化为代码块。因为我们可以自己测试代码,所以它对您来说速度更快,也让我们的生活更轻松。我不确定您是否必须直接调用cmd.exe。您应该能够运行批处理文件。否则,您可以使用shellexecute API。转录代码(非常辛苦)为什么不干脆
Shell(“c:\apps\test.bat”,1)
 stAppName = "c:\apps\test.bat"