didrocks
Messages postés73Date d'inscriptionsamedi 11 janvier 2003StatutMembreDernière intervention17 décembre 2007
-
8 juin 2005 à 16:03
didrocks
Messages postés73Date d'inscriptionsamedi 11 janvier 2003StatutMembreDernière intervention17 décembre 2007
-
8 juin 2005 à 18:03
Bonjour tout le monde!
J'aimerais qu'à chaque enregistrement de mon fichier excel (enregistré dans un répertoire temporaire), celui-ci s'envoie par ftp sur un serveur donné. Or ceci ne semble pas fonctionner (cela marche très bien quand je donne le chemin d'un autre fichier, mais pas quand j'essaie avec mon fichier qui est par conséquent ouvert)
Voici mon code dans mon classeur:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not (iPremierEnregistrement) Then
iPremierEnregistrement = True ' empêche l'enregistrement de l'enregistrement
' l 'enregistre
ThisWorkbook.Save
' envoie par ftp
Call EnregistreParFtp(strCmdArgs(1), CInt(strCmdArgs(2)), strCmdArgs(3), strCmdArgs(4), strCmdArgs(5), strCmdArgs(7))
iPremierEnregistrement = False
' ne le réenregistre pas
Cancel = True
End If
End Sub
et dans un module:
Option Explicit
Const FTP_TRANSFER_TYPE_ASCII = &H1
Const INTERNET_SERVICE_FTP = 1
Const INTERNET_FLAG_PASSIVE = &H8000000
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private 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
Private 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
Private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hConnect As Long, ByVal lpszLocalFile As String, ByVal lpszNewRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean
Private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean
Private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String, lpdwCurrentDirectory As Long) As Long
' envoie par ftp
Public Sub EnregistreParFtp(strServeur As String, iPort As Integer, strLogin As String, strMdp As String, strChemin As String, strNomFichierDestination As String)
Dim hopen As Long, hConnection As Long
hopen = InternetOpen(strServeur, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hConnection = InternetConnect(hopen, strServeur, iPort, strLogin, strMdp, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE, 0)
' set le rep courant
FtpSetCurrentDirectory hConnection, strChemin
' fichier sur local nom fichier sur FTP
FtpPutFile hConnection, RecupCheminTemp & strNomFichierDestination & ".xls", strNomFichierDestination & ".xls", FTP_TRANSFER_TYPE_ASCII, 0
' ferme la connection
InternetCloseHandle hConnection
End Sub
Y a t'il un moyen d'envoyer par ftp mon fichier en cours, à chaque enregistrement?