1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" ( _
ByVal hInternetSession As Long, ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long
Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
ByVal sAgent As String, ByVal lAccessType As Long, _
ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias _
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, _
ByVal lpszDirectory As String) As Boolean
Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" ( _
ByVal hConnect As Long, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByRef dwContext As Long) As Boolean
Sub cherche()
Dim Nom As String
Dim chemin As String
Nom = ActiveCell.Value + ".xls"
chemin = "C:\dossier1\" + Nom
internet_ok = InternetOpen("", 1, "", "", 0)
If internet_ok Then
ftp_ok = InternetConnect(internet_ok, "serveur.com", 21, "login", "motdepasse", 1, 0, 0)
If FtpSetCurrentDirectory(ftp_ok, "/dossier2") Then
succès = FtpGetFile(ftp_ok, Nom, chemin, False, 0, &H0, 0)
End If
End If
If succès = False Then MsgBox ("le fichier '" + Nom + "' n'a pas été trouvé!")
If succès Then
Workbooks.Open Filename:=chemin
End If
End Sub |
Partager