为什么用shell调用bat文件会报无效的过程调用或参数的错误??请高手指点迷津!!!
Private Sub cmdshangbao_Click()
Dim i, j, k As Integer
Dim int_file As Integer
Dim filename As String
Dim filepath As String
Dim fso1, fso2
Dim fil1, fil2
Dim RetVal
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set fil1 = fso1.CreateTextFile("c:\ftp_file.txt", True)
fil1.writeline ("open 192.168.1.120")
fil1.writeline ("user audit01 123456 ")
Set fso2 = CreateObject("Scripting.FileSystemObject")
Set fil2 = fso2.CreateTextFile("c:\ftp_file.bat", True)
fil2.writeline ("ftp -in < ftp_file.txt")
If Me.ListBox1.ListCount = 0 Then
MsgBox "没有文件,退出!"
Exit Sub
End If
int_file = Me.ListBox1.ListCount
For i = 0 To int_file - 1
filename = Trim(Me.ListBox1.List(i))
filepath = "put " & ActiveWorkbook.Path & "\" & filename & " " & filename
fil1.writeline (filepath)
Next
fil1.writeline ("by ")
RetVal = Shell("c:\ftp_file.bat", vbMaximizedFocus) '这里总是报无效的过程调用或参数,为啥fil1.Close
fil2.Close
MsgBox "文件上传完成!"
Kill "c:\ftp_file.txt"
Kill "c:\ftp_file.bat"
End Sub
[解决办法]
改为
RetVal = Shell("cmd /c c:\ftp_file.bat", vbNormalFocus)
试试
[解决办法]
C/前后各一个空格,vbNormalFocus无所谓.
[解决办法]
Shell("cmd /c c:\ftp_file.bat")仅是调用cmd.EXE去执行c:\ftp_file.bat文件,仅此而已.
[解决办法]
去掉参数/c 试一下:
Shell("cmd c:\ftp_file.bat")