2010-05-26 77 views
2

我有一个Excel工作表,用户在其中输入某些数据,我想将其存储在文本文件中并使用FTP上传到服务器。一个站点建议添加对“Microsoft Internet Transfer Control”的引用,然后定义一个“Inet”对象来执行FTP。但是,我无法在VB编辑器的“工具 - >参考”中找到此名称的参考。有谁知道这个问题的解决方案?提前致谢。在Excel中使用VBA将文本文件传输到服务器

回答

5

这里是一个解决方案,我发现做了一些谷歌搜索 -

Public Sub FtpSend() 

Dim vPath As String 
Dim vFile As String 
Dim vFTPServ As String 
Dim fNum As Long 

vPath = ThisWorkbook.Path 
vFile = "YourFile.csv" 
vFTPServ = "********" 

'Mounting file command for ftp.exe 
fNum = FreeFile() 
Open vPath & "\FtpComm.txt" For Output As #fNum 
Print #1, "user ***** *****" ' your login and password" 
Print #1, "cd TargetDir" 'change to dir on server 
Print #1, "bin" ' bin or ascii file type to send 
Print #1, "put " & vPath & "\" & vFile & " " & vFile ' upload local filename to server file 
Print #1, "close" ' close connection 
Print #1, "quit" ' Quit ftp program 
Close 

Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbNormalNoFocus 

SetAttr vPath & "\FtpComm.txt", vbNormal 
Kill vPath & "\FtpComm.txt" 

End Sub 

原始来源:http://www.access-programmers.co.uk/forums/showthread.php?t=184692

+0

这里是一个[ShellWait(http://access.mvps.org/access/api /api0004.htm)函数来封装Shell调用。它将等到shell命令(上面的ftp函数)完成后再继续。它来自访问网站,但应该适用于任何vba主机。 – 2016-08-11 21:15:43

相关问题