zaman ayarlı otomatik FTP upload

Katılım
26 Şubat 2017
Mesajlar
1
Excel Vers. ve Dili
2016 Türkçe
İlk olarak makroyla tanışmış biri olarak aşağıda takıldım kaldım.

DDE link ile otomatik güncellenen bir excel dosyam var.

Burada belirli bir alanı web dosyası olarak 10 dakikada bir FTP ile upload etmek istiyorum.

Aşağıdaki gibi bir kod buldum ama bunu nasıl kendime uygulayacağımı bulamadım. Yardımcı olabilir misiniz?

Const cFTPServer As String = "ftp.mysite.com" 'CHANGE THIS.
Const cFTPPort = 21
Const cFTPCommandsFile As String = "FTP_commands.txt"


Public Sub Ftp_Upload_File()

Dim inputValue As Variant
Dim FTPusername As String, FTPpassword As String
Dim filenum As Integer
Dim FTPcommand As String
Dim wsh As Object

inputValue = InputBox("Enter username", cFTPServer)
If inputValue = False Or inputValue = "" Then Exit Sub
FTPusername = CStr(inputValue)

inputValue = InputBox("Enter password for username " & FTPusername, cFTPServer)
If inputValue = False Or inputValue = "" Then Exit Sub
FTPpassword = CStr(inputValue)

'Create file containing ftp commands. The file has to contain the username and password
'to connect to the ftp server. Creating the file and deleting it immediately after use gives some degree of
'security in preference to having a static file containing the username and password

filenum = FreeFile
Open cFTPCommandsFile For Output As #filenum
Print #filenum, "!REM upload .csv file" 'Use !REM for comments with a Windows ftp server
'Print #filenum, "!# upload .csv file" 'Use '# for comments with a Unix ftp server
Print #filenum, "open " & cFTPServer & " " & cFTPPort
Print #filenum, "user " & FTPusername & " " & FTPpassword
Print #filenum, "cd Website-Search"
Print #filenum, "binary"
Print #filenum, "put " & QQ(ThisWorkbook.Path & "\System\Website-Search-File\Website-Search.csv")

'The next line is temporarily commented out to omit the bye command from the ftp commands script.
'This keeps the command window open to show whether the ftp commands worked successfully or not.
'If the bye command is omitted you must type bye in the command window to exit ftp and end this procedure

'Print #filenum, "bye"
Close #filenum

'Construct ftp command line, specifying the file containing FTP commands. The -n parameter suppresses auto-login
'upon initial connection because we want to use the username and password specified in the command file

FTPcommand = "ftp -i -n -s:" & QQ(cFTPCommandsFile)

'Run ftp command synchronously, waiting for the command to return
'WindowStyle 1 displays the command window. Use this, together with omitting the bye command, to verify
'whether or not the ftp commands worked successfully.
'WindowStyle 0 hides the command window.
'See http://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx

CreateObject("WScript.Shell").Run Command:=FTPcommand, WindowStyle:=1, waitonreturn:=True

'Delete the ftp commands file so that the username and password are not left lying around

Kill cFTPCommandsFile

MsgBox "Finished"

End Sub

Private Function QQ(text As String) As String
QQ = Chr(34) & text & Chr(34)
End Function
Kaydedebildiğim htm olarak save etme makrosu şöyle :

Sub Makro1()
'
' Makro1 Makro
'
' Klavye Kısayolu: Ctrl+h
'
Range("A1:D27").Select
Range("D27").Activate
With ActiveWorkbook.PublishObjects("gunson_29602")
.Publish (False)
.AutoRepublish = False
End With
End Sub
 
Üst