Bestand downloaden en opslaan op d-schijf

Status
Niet open voor verdere reacties.

bjorn1976

Gebruiker
Lid geworden
31 okt 2006
Berichten
9
Wie kan mij helpen met mijn macro.

ik wil graag een bestand van het web downloaden, en deze dan automatisch opslaan op mijn d-schijf.

ben even bezig geweest met hyperlink.follow maar dat is me niet gelukt.
 
Hij is opgelost




Function SaveWebFile(ByVal vWebFile As String, ByVal vLocalFile As String) As Boolean
Dim oXMLHTTP As Object, i As Long, vFF As Long, oResp() As Byte

'You can also set a ref. to Microsoft XML, and Dim oXMLHTTP as MSXML2.XMLHTTP
Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP")
oXMLHTTP.Open "GET", vWebFile, False 'Open socket to get the website
oXMLHTTP.Send 'send request

'Wait for request to finish
Do While oXMLHTTP.readyState <> 4
DoEvents
Loop

oResp = oXMLHTTP.responseBody 'Returns the results as a byte array

'Create local file and save results to it
vFF = FreeFile
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF

'Clear memory
Set oXMLHTTP = Nothing
End Function

Sub TestingTheCode()
'This will save the Google logo to your hard drive, insert it into the
' active spreadsheet, then delete the local file
SaveWebFile "http://www.google.com/intl/en/images/logo.gif", "C:\GoogleLogo.gif"
ActiveSheet.Pictures.Insert "C:\GoogleLogo.gif"
Kill "C:\GoogleLogo.gif"
End Sub
 
Dat kan simpeler:

Code:
Private Declare Function DownloadWebFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long

Sub tst2()
    DownloadWebFile 0, "http://www.advanscene.com/offline/datas/ADVANsCEne_NDS_S.zip", "E:\ADVANsCEne_NDS_S.zip", 0, 0
End Sub
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan