0
Sub Button1_Click()
Dim a
ipaddress = ActiveSheet.Cells(3, 2).Value
UserName = ActiveSheet.Cells(4, 2).Value
Password = ActiveSheet.Cells(5, 2).Value
Path = ActiveSheet.Cells(6, 2).Value
a = ActiveSheet.Cells(7, 2).Value 'Reports needs to be downloaded
aSplit = Split(a, ",")
Const ForWriting = 2
Dim objOutStream, objjFSO, objShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutStream = objFSO.OpenTextFile("C:\Documents and Settings\FTPCommand.txt",      ForWriting, True)
With objOutStream
.WriteLine UserName
.WriteLine Password
.WriteLine "binary"
.WriteLine Path
For i = 0 To UBound(aSplit)
    aSplit(i) = Trim(aSplit(i))
    .WriteLine "get ES." & aSplit(i)
Next
.WriteLine "quit"
.Close
End With
Set objShell = CreateObject("WScript.Shell")
objShell.Run "%comspec% /k FTP -n -i -s:" & "C:\Documents and Settings\FTPCommand.txt" & " " & ipaddress, 1, True
End Sub

运行宏代码后的文本文件:

Username
Password
binary
Path
get ES.1312
get ES.3243
get ES.4534
quit

文本文件中的命令不执行。我不知道如何解决它。

请帮助...提前感谢您的帮助。

4

1 回答 1

1

路径有空格,所以必须用引号将其与命令行的其他部分区分开来:

objShell.Run "%comspec% /k FTP -n -i -s:" & """C:\Documents and Settings\FTPCommand.txt""" & " " & ipaddress, 1, True
于 2012-10-10T11:00:57.840 回答