GNT sans publicité, site mobile, fonctionnalitées exclusives...

Pause dans une macro transfert FTP et Recup d'un fichier TEXTE Suite...

Le
Domi
Bonjour,
Ce message fait suite au premier pour lequel je demandais comment inserer
une commande de transfert FTP dans une macro.
La solution proposée par MichDenis convient parfaitement.
Le problème se pose ensuite lorsque je dois mettre en forme le fichier texte
récupéré. Cela plante car le fichier est toujours en cours de transfert
lorsque la procédure se pousuit (Traitement). Qulqu'un aurait-il la solution
à ce problème ?
Merci
Domi


Sub testTransfert()
'Importation du fichier txt
Shell "C:\WINDOWS\system32\ftp.exe -s:c:\transfert\transf.txt
192.x.x.x", vbNormalFocus 'vbHide

'''''Comment ne faire executer la suite qu'à la fin du transfert ? (lorque
la fenêtre de transfert se ferme.)

'Traitement du fichier txt
Workbooks.OpenText Filename:="C:\TRANSFERT\toto.txt",
Origin:=xlWindows,StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2),
Array(25 , 2), Array(44, 2), Array(53, 1), Array(66, 1), Array(79,
1),Array(92, 9), Array(102, 4), Array(110, 9), Array(124, 2), Array(129,
2), Array(132, 9))

etc..
End Sub
Lire les 9 réponses

Vidéos High-Tech et Jeu Vidéo
Téléchargements
Vos réponses Page 1 / 2
Gagnez chaque mois un abonnement Premium avec GNT : Inscrivez-vous !
Trier par : date / pertinence
Daniel
Le #4107201
Bonjour.
Essaie :

On Error Resume Next
Do
Err.Clear
Application.Wait Now + TimeValue("00:03:00")
Workbooks.OpenText Filename:="C:TRANSFERTtoto.txt", _
Origin:=xlWindows, StartRow:=1, DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 2), _
Array(25, 2), Array(44, 2), Array(53, 1), Array(66, 1), Array(79, _
1), Array(92, 9), Array(102, 4), Array(110, 9), Array(124, 2), Array(129, _
2), Array(132, 9))
Loop While Err.Number <> 0
On Error GoTo 0

Le délai est réglé sur 3 mn. A modifier suivant la taille du fichier à
transmettre.
Cordialement.
Daniel
"Domi"
Bonjour,
Ce message fait suite au premier pour lequel je demandais comment inserer
une commande de transfert FTP dans une macro.
La solution proposée par MichDenis convient parfaitement.
Le problème se pose ensuite lorsque je dois mettre en forme le fichier
texte récupéré. Cela plante car le fichier est toujours en cours de
transfert lorsque la procédure se pousuit (Traitement). Qulqu'un aurait-il
la solution à ce problème ?
Merci
Domi


Sub testTransfert()
'Importation du fichier txt
Shell "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt
192.x.x.x", vbNormalFocus 'vbHide

'''''Comment ne faire executer la suite qu'à la fin du transfert ? (lorque
la fenêtre de transfert se ferme....)

'Traitement du fichier txt
Workbooks.OpenText Filename:="C:TRANSFERTtoto.txt",
Origin:=xlWindows,StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2),
Array(25 , 2), Array(44, 2), Array(53, 1), Array(66, 1), Array(79,
1),Array(92, 9), Array(102, 4), Array(110, 9), Array(124, 2), Array(129,
2), Array(132, 9))

etc.....
End Sub




MichDenis
Le #4107161
Copie tout ce qui suit dans un module standard :

'Section Variables et API dans le haut du module standard
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long

Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&


Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

start.cb = Len(start)

ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub

Et dans ta macro, tu passes la ligne suivante
'----------------------
ExecCmd Shell(" Shell "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x",
vbNormalFocus 'vbHide")
'----------------------

Et le reste de ton code ici ....




"Domi" Bonjour,
Ce message fait suite au premier pour lequel je demandais comment inserer
une commande de transfert FTP dans une macro.
La solution proposée par MichDenis convient parfaitement.
Le problème se pose ensuite lorsque je dois mettre en forme le fichier texte
récupéré. Cela plante car le fichier est toujours en cours de transfert
lorsque la procédure se pousuit (Traitement). Qulqu'un aurait-il la solution
à ce problème ?
Merci
Domi


Sub testTransfert()
'Importation du fichier txt
Shell "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt
192.x.x.x", vbNormalFocus 'vbHide

'''''Comment ne faire executer la suite qu'à la fin du transfert ? (lorque
la fenêtre de transfert se ferme....)

'Traitement du fichier txt
Workbooks.OpenText Filename:="C:TRANSFERTtoto.txt",
Origin:=xlWindows,StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2),
Array(25 , 2), Array(44, 2), Array(53, 1), Array(66, 1), Array(79,
1),Array(92, 9), Array(102, 4), Array(110, 9), Array(124, 2), Array(129,
2), Array(132, 9))

etc.....
End Sub
Domi
Le #4106241
Bonjour,
J'ai testé au boulot. Pas de pb pour la recopie intégrale dans un module...
c'est à ma portée ;o)
Par contre petit souci, dont je ne parviens pas à trouver la cause sur la
ligne de commande Sheel modifiée dans la macro de traitement

ExecCmd Shell(" Shell
"C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x",

Sur le premier C (de C:Windows.....) j'ai à l'execution un message
d'erreur : "Erreur de compilation, Attendu : Séparateur de liste ou)
A+
Domi

"MichDenis"
Copie tout ce qui suit dans un module standard :

'Section Variables et API dans le haut du module standard
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long

Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
As Long) As Long

Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&


Public Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

start.cb = Len(start)

ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub

Et dans ta macro, tu passes la ligne suivante
'----------------------
ExecCmd Shell(" Shell
"C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x",
vbNormalFocus 'vbHide")
'----------------------

Et le reste de ton code ici ....




"Domi"
Bonjour,
Ce message fait suite au premier pour lequel je demandais comment inserer
une commande de transfert FTP dans une macro.
La solution proposée par MichDenis convient parfaitement.
Le problème se pose ensuite lorsque je dois mettre en forme le fichier
texte
récupéré. Cela plante car le fichier est toujours en cours de transfert
lorsque la procédure se pousuit (Traitement). Qulqu'un aurait-il la
solution
à ce problème ?
Merci
Domi


Sub testTransfert()
'Importation du fichier txt
Shell "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt
192.x.x.x", vbNormalFocus 'vbHide

'''''Comment ne faire executer la suite qu'à la fin du transfert ? (lorque
la fenêtre de transfert se ferme....)

'Traitement du fichier txt
Workbooks.OpenText Filename:="C:TRANSFERTtoto.txt",
Origin:=xlWindows,StartRow:=1, DataType:=xlFixedWidth,
FieldInfo:=Array(Array(0, 2),
Array(25 , 2), Array(44, 2), Array(53, 1), Array(66, 1), Array(79,
1),Array(92, 9), Array(102, 4), Array(110, 9), Array(124, 2), Array(129,
2), Array(132, 9))

etc.....
End Sub





MichDenis
Le #4106161
| ExecCmd Shell(" Shell
| "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x",

Si tu observes la syntaxe suggérée de la ligne de code suggéré, tu
devrais avoir :

ExecCmd Shell("Shell "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x", vbHide")
Domi
Le #4105571
Bonjour,
Je met un peu de temps pour répondre parce je teste au boulot...
Je ne comprends pas, si je copie sans le moindre changement (à part lIP)
j'ai systématiquement un message d'erreur de syntaxe...
J'ai essayé un peu tout mais en vain ! le premier Shell que tu m'a proposé
marche pourtant impec mais ave le 2eme ça ne passe plus, je me doute que ça
doit pas être grand chose mais je ne vois vraiment pas quoi.
As la possiblité de tester une telle procédure ?
MErci pour ton aide
Domi

"MichDenis" %

| ExecCmd Shell(" Shell
| "C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x",

Si tu observes la syntaxe suggérée de la ligne de code suggéré, tu
devrais avoir :

ExecCmd Shell("Shell
"C:WINDOWSsystem32ftp.exe -s:c:transferttransf.txt 192.x.x.x",
vbHide")






Publicité
Suivre les réponses
Poster une réponse
Anonyme