Bonjour,
Dehbi m'a demandé de l'aide en mp pour télécharger un fichier texte distant sans connaître les identifiants ftp.
Il y a une partie qu'il voulait confidentielle mais qui n'apporte rien ici car il s'agissait de lire et décoder une page html contenant les noms des fichiers texte.
Par contre, il m'a semblé intéressant de partager ici les différentes solutions proposées ... mais bien sûr je suis aussi à l'écoute de vos solutions.
Notepad++ : permet d'ouvrir un fichier distant, mais je n'ai pas réussi à automatiser cette partie en macro
Sub Telecharger_notepad(fichier As String)
Shell "C:\Program Files (x86)\Notepad++\notepad++.exe " & fichier
End Sub
Excel : solution intéressante mais qui a le désavantage de transformer le fichier lui-même !!
Sub Telecharger_excel(fichier As String)
Dim myfile As Workbook
Workbooks.OpenText Filename:=fichier
Set myfile = ActiveWorkbook
Application.DisplayAlerts = False
myfile.SaveAs Environ("USERPROFILE") & "\Desktop\" & Split(fichier, "/")(UBound(Split(fichier, "/")))
myfile.Close
Application.DisplayAlerts = True
End Sub
Google chrome : fonctionnement correct
Sub Telecharger_chrome(fichier As String)
Call Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & " -url" & " " & fichier, vbMaximizedFocus)
Application.Wait Now + TimeValue("0:00:03")
'AppActivate fichier & " - Google Chrome"
Application.SendKeys ("^s")
Application.Wait Now + TimeValue("0:00:01")
Application.SendKeys ("%e")
Application.Wait Now + TimeValue("0:00:01")
'Application.SendKeys ("%{F4}")
End Sub
IE : ok
Sub Telecharger_IE(fichier As String)
Dim folder As String
folder = Environ("USERPROFILE") & "\Desktop\"
With CreateObject("InternetExplorer.Application")
.Visible = False
.navigate fichier
While .Busy Or .readyState <> 4: DoEvents: Wend
While .document.readyState <> "complete": DoEvents: Wend
Open folder & Split(fichier, "/")(UBound(Split(fichier, "/"))) For Output As #1
Print #1, .document.body.innerText
Close #1
End With
End Sub
solution retenue
Il va de soi que le fichier doit pouvoir être "public" même si les identifiants serveur sont inconnus.