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
|
Private Sub DownloadFromDropbox()
On Error GoTo Erreur
Dim xmlhttp As Object
Set xmlhttp = CreateObject("MSXML2.serverXMLHTTP")
Dim Fichier As Long
Dim myURL As String
Dim ConvertToSave() As Byte
Dim fichier_local
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(&H5) 'répertoire documents
Set objFolderItem = objFolder.Self
fichier_local = objFolderItem.Path & "\" & "fichier_test.txt"
'ici est indiqué le lien de partage dropbox ; normalement celui-ci est extrait d'une cellule du classeur pour faciliter la mise à jour
myURL = "https://www.dropbox.com/s/023gihe9efxe77x/fichier%20test%20download.txt?dl=1"
xmlhttp.Open "GET", myURL, False
xmlhttp.send
h = FreeFile
FileName = fichier_local
ConvertToSave() = xmlhttp.responseBody
Open FileName For Binary As #h
Put #h, 1, ConvertToSave()
Close #h
MsgBox Prompt:="Nouveau fichier récupéré." & vbCrLf & "Vous pouvez procéder à son utilisaton.", Buttons:=vbOKOnly, Title:="Nouveau fichier"
Application.Cursor = xlDefault
Shell "C:\windows\explorer.exe " & objFolderItem.Path, vbNormalFocus
Exit Sub
Erreur:
MsgBox "Une erreur s'est produite, veuillez relancer la procédure."
End Sub |
Partager