macro qui ne fonctionne pas quand j'ai certaines lignes

klorane

XLDnaute Occasionnel
Lors que j'ai les lignes ci-dessous dans la macro celle ci ne trnasfert pas mon fichier sur le serveur ftp et quand je les retire ça fonctionne.

Quelqu'un c'est il pourquoi? et comment remédier au problème...

Merci

Laurent

------
'ici lignes bloquant ma macro : placée à plus b as dans la macro voir l'emplacement : SONT ICI

ActiveWorkbook.Save
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\essais\Dues2.xls", FileFormat:=xlNormal, CreateBackup:=False
ActiveWorkbook.SaveAs Filename:="C:\essais\Dues2.htm", FileFormat:=xlHtml, CreateBackup:=False
----


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 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 FtpSetCurrentDirectory Lib "wininet.dll" Alias _
"FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, _
ByVal lpszDirectory As String) As Boolean
Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" ( _
ByVal hFtpSession As Long, _
ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean
Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer


Sub ftp()

'LES LIGNES ci dessus sont placées ICI

'transfère des fichiers du disque local vers un serveur ftp (upload, mode passif)

'PARAMETRES************************
fichier = "c:\essais\Dues2.htm"
login = "monlogin"
mot_passe = "monmotdepasse"
rép = "/monrepertoire"
bin_asc = &H2 '(&H1 ascii, &H2 binaire)
Mode = &H8000000 '(&H8000000 mode passif, 0 mode actif)
'**********************************

'lancer le transfert
internet_ok = InternetOpen("PutFtpFile", 1, "", "", 0)
If internet_ok = 0 Then
MsgBox "connection internet impossible"
Exit Sub
End If
ftp_ok = InternetConnect(internet_ok, "ftpperso.free.fr", 21, login, mot_passe, 1, Mode, 0)
If ftp_ok = 0 Then
MsgBox "connection impossible"
Exit Sub
End If
sélect_rép = FtpSetCurrentDirectory(ftp_ok, rép)
If sélect_rép = 0 Then
MsgBox "impossible de trouver le répertoire "
Exit Sub
End If

'nom du fichier sans le chemin
nomfich = fichier
Do While InStr(nomfich, "\") > 0
nomfich = Right(nomfich, Len(nomfich) - InStr(nomfich, "\"))
Loop

'transférer le fichier
succès = FtpPutFile(ftp_ok, fichier, nomfich, bin_asc, 0)
If succès Then
résult = nomfich & " a été transféré "
Else
résult = nomfich & " n'a pas pu être transféré"
End If

'fermer les pointeurs, ménage
InternetCloseHandle ftp_ok
InternetCloseHandle internet_ok

'annoncer le résultat de l'opération
If résult <> "" Then
MsgBox résult
Else
MsgBox "aucun fichier transféré"
End If

End Sub
 

Discussions similaires

Statistiques des forums

Discussions
312 329
Messages
2 087 329
Membres
103 517
dernier inscrit
hbenaoun63