Question : VBA Macro to edit .bat file

Hello Experts,

     I am in the process of creating some VBA macros that will initiate a DOS script in a batch file that will run FTP.  Below is the DOS Script...

@echo off

set /p ftp_file_date=Please enter the transaction file date (YYMMDD):
set /p ftp_user=Please enter your PMTDEV user name:
set /p ftp_pass=Please enter your password:

>> C:\script.ftp echo open pmtdev.safeway.com
>> C:\script.ftp echo %ftp_user%
>> C:\script.ftp echo %ftp_pass%
>> C:\script.ftp echo lcd c:\
>> C:\script.ftp echo cd 51.swyut
>> C:\script.ftp echo ascii
>> C:\script.ftp echo prompt
>> C:\script.ftp echo mget V?%ftp_file_date%
>> C:\script.ftp echo bye
%windir%\system32\ftp.exe -s:C:\script.ftp
del C:\script.ftp
cls
exit

     This script asks users for a date, username, and password.  Using the user entered info, the script initiates an FTP session, logs in, transfers files based on the user entered date, then closes the FTP session.
     My ultimate goal is to entirely automate the FTP process.  My intent is to have the user enter their FTP logon and password in a user form in Excel, since I can mask the password in Excel, and can't efficiently mask the password in the DOS script.  The information the user has entered in Excel would be stored in variables.  From there, I'd like to insert these variable into the DOS script.  This way, the files are FTP'd to the local destination, without the password being compromised.

     So, if someone can help me to pass the Excel variables to the DOS script, I'd really appreciate it.

Thanks,

Jeremy

Answer : VBA Macro to edit .bat file

try using this sub

Sub subFTPOutput()
    f = "C:\script.ftp"
    Open f For Output As #1
    Print #1, "open pmtdev.safeway.com"
    Print #1, txtUser
    Print #1, txtPass
    Print #1, "lcd c:\"
    Print #1, "cd; 51#; swyut"
    Print #1, "ascii"
    Print #1, "prompt"
    Print #1, "mget V?" & txtDate
    Print #1, "bye"
    Close #1
    Shell "c:\windows\system32\ftp.exe -s:C:\script.ftp"
    Kill "C:\script.ftp"

End Sub

I hope this helps.
-David251
Random Solutions  
 
programming4us programming4us