Download file from net and save as txt-file

D

Dala

Hello.

I would like some help on how I can download a file from the web and save it
as a text file.

Say the URL looks something like this
http://se.domain.com/files/yourfile.txt

I would like to save this file as a textfile in a local folder and name the
file with name, date and time, since I have to download the same file
multiple times and the file will contain different data each time even if it
has the same URL.

If it were only a few times, then I could do it manually or with FF add-on,
but it has to be done over and over again, so I really need to automate it
and then I thought of Access to handle the job.

I have searched and I can not really find what I am looking for.
I feel I have been close to find solutions, but when I have tested them they
dont really work for me.

Anyone who feel they want to give me a hand with this?

Thanks in advance!!!
 
D

Douglas J. Steele

Declare Function URLDownloadToFile _
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

Private Function DownloadFile( _
URL As String, _
LocalFilename As String _
) As Boolean
On Error GoTo Err_DownloadFile

Dim lngRetVal As Long

lngRetVal = _
URLDownloadToFile(0, URL, LocalFilename, 0, 0)
DownloadFile = (lngRetVal = 0)

End Function


Use it like

Call DownloadFile("http://se.domain.com/files/yourfile.txt",
"C:\Folder\yourfile.txt")

(just in case it gets messed up in the post, that's supposed to be all one
line of text, and the URL and file name are both enclosed in double quotes)
 
D

Dala

Thanks alot!!!
That did the trick.

I had to change it to a public function to make it work though, but
otherwise it was all I dreamed of. ;)

Thank you for your time.
 
D

Douglas J. Steele

Hmm. Sorry I didn't notice the Private declaration. That was copied from an
article I wrote for Access Advisor about interacting with the internet using
Access: there must have been a reason why I made it private in there, but
darned if I can think of it now!

Glad you got it working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top