I need a simple script to do the following in an Excel macro

1.) Open Internet Explore
2.) Go to a specific URL
3.) Download a file
4.) save it to my computer for future use with macro.

I have been working at this and the only thing I can get working is step 1.

Any help would be greatly appreciated.

Re: VB script to download txt file by Anthony

Anthony
Thu Nov 29 14:11:24 PST 2007

"Megadrone" <Megadrone@discussions.microsoft.com> wrote in message
news:80F6D2F7-0BF2-43D7-85B3-882DFEC2B487@microsoft.com...
> I need a simple script to do the following in an Excel macro
>
> 1.) Open Internet Explore
> 2.) Go to a specific URL
> 3.) Download a file
> 4.) save it to my computer for future use with macro.
>
> I have been working at this and the only thing I can get working is step
1.
>
> Any help would be greatly appreciated.

Dim oWinHTTP
Dim oStream

Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")

oWinHTTP.Open "GET", "http://remoteserver/file.dat", False
oWinHTTP.Send

If oWinHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write oWinHTTP.responseBody
oStream.SaveToFile "c:\temp\file.dat"
oStream.Close
End If


--
Anthony Jones - MVP ASP/ASP.NET