I am trying to automate the following process:
- Data imported to Microsoft Excel (
myfile.xls
) from database and formatted. - File saved as
myfile.txt
. - Uploaded via
FTP
to a server.
I have got as far as the FTP
upload, but I am having issues with the batch file created within the VBA
script.
The current script I have is as follows:
Dim MY_FILENAME As String
MY_FILENAME = "C:\user\sam\test" & "filename" & Format(CStr(Now), "yyyy_mm_dd_hh_mm") & ".BAT"
Dim FileNumber As Integer
Dim retVal As Variant
FileNumber = FreeFile
'create batch file
Open MY_FILENAME For Output As #FileNumber
Print #FileNumber, "FTP 00.0.000.000"
Print #FileNumber, "username"
Print #FileNumber, "password"
Print #FileNumber, "ascii crlf"
Print #FileNumber, "put " myfile.txt; " 'location'"
Print #FileNumber, "exit"
Close #FileNumber
'run batch file
retVal = Shell(MY_FILENAME, vbNormalFocus)
When I run this script, it opens the IP associated to the server, but fails to enter the login credentials. Can anyone advise where I am going wrong?