Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Copy a file from Internet

127 views
Skip to first unread message

Sergio Luis Martins

unread,
Jun 20, 2002, 6:34:10 PM6/20/02
to
I know you can copy a file by VBA from one folder to another folder on local
drive like this:

FileCopy "c:\onefolder\myfile", "c:\anotherfolder\myfile"

I ask, is it possible do this by VBA from Internet? Somethig like this:

NewFileCopy "http://www.server.com/myfile" , "c:\myfolder\myfile"

TIA

Sergio


dermot

unread,
Jun 20, 2002, 7:56:07 PM6/20/02
to
Sergio

You can open an Excel file on the internet from Excel, but
I don't think you can copy it. I have examples on my site
below of how you can download files from the net, though...

Dermot Balson
Free VBA code for encryption, compression, internet
connectivity
http://www.webace.com.au/~balson/InsaneExcel/Default.html
Last updated 6 June 2002

>.
>

Jake Marx

unread,
Jun 21, 2002, 2:33:44 AM6/21/02
to
Hi Sergio,

Yes, you can do this. But no, it's not as simple as it should be (unless
I'm missing something). Here's a routine I came up with that will copy a
file via HTTP to the location of your choice. It uses the ADODB.Stream
object, as well as the XMLHTTP object. I haven't tested this routine very
much (plus it's late here and I'm tired), but it seems to work ok.

To use this, you must set references to the Microsoft ADO and Microsoft XML
libraries via Tools | References in the VBE.

Regards,

Jake Marx
MS MVP - Excel

'/--------------------CODE BEGINS HERE------------------------
Public Sub CopyFileViaHTTP(rsURL As String, _
rsFilePath As String, Optional rbOverwrite _
As Boolean = False)
Dim objXML As XMLHTTP
Dim objStream As ADODB.Stream
Dim lOverwrite As Long

On Error GoTo ErrHandler

Set objXML = New XMLHTTP

With objXML
.Open "GET", rsURL, False
.send
If .Status >= 400 And .Status <= 599 Then _
Err.Raise 10001, "CopyFileViaHTTP", "Unable to download" _
& " file '" & rsURL & "'."
End With

Set objStream = New ADODB.Stream

With objStream
.Open
.Type = adTypeBinary
.Write objXML.responseBody
If rbOverwrite Then
lOverwrite = ADODB.SaveOptionsEnum.adSaveCreateOverWrite
Else
lOverwrite = ADODB.SaveOptionsEnum.adSaveCreateNotExist
End If
.SaveToFile rsFilePath, lOverwrite
.Close
End With

ExitRoutine:
If Not objStream Is Nothing Then
If objStream.State = adStateOpen Then objStream.Close
Set objStream = Nothing
End If
Set objXML = Nothing
Exit Sub
ErrHandler:
MsgBox "Error #: " & CStr(Err.Number) & vbLf & _
"Description: " & Err.Description, vbExclamation, _
"ERROR"
Resume ExitRoutine
End Sub
'/--------------------CODE ENDS HERE------------------------

"Sergio Luis Martins" <sergi...@uol.com.br> wrote in message
news:u6DOStKGCHA.2520@tkmsftngp13...

Ron de Bruin

unread,
Jun 21, 2002, 10:42:01 AM6/21/02
to
You can do somthing like this to do

Sub test()
Set a = Workbooks.Open("http://www.site.com/ron.xls")
a.SaveAs "c:/test.xls"
End Sub

Regards Ron

"Sergio Luis Martins" <sergi...@uol.com.br> schreef in bericht
news:u6DOStKGCHA.2520@tkmsftngp13...

Sergio Luis Martins

unread,
Jun 25, 2002, 12:09:20 AM6/25/02
to
Thanks Dermot for your reply, but my knowledge isn't sufficient to handle
API. And congratulations you're really a expert VB.

Regards,

Sergio


"dermot" <dermotbalso...@hotmail.com> escreveu na mensagem
news:10b6401c218b6$0b694cc0$9be62ecf@tkmsftngxa03...

Sergio Luis Martins

unread,
Jun 25, 2002, 12:16:49 AM6/25/02
to
Thanks, Jake Marx. Maybe your code is just I want, but, although I have
Office XP professional installed, I didn't find the libraries for
ADODB.Stream objects. Do you know the DLL name?

Regards,

Sergio Luis

"Jake Marx" <ja...@longhead.com> escreveu na mensagem
news:uu1dK1OGCHA.2312@tkmsftngp12...

Sergio Luis Martins

unread,
Jun 25, 2002, 12:19:27 AM6/25/02
to
Thanks Ron de Bruin for your reply, but I need to copy files with not Excel
format.

Regards,

Sergio Luis

"Ron de Bruin" <ronde...@kabelfoon.nl> escreveu na mensagem
news:uaVFzGTGCHA.1288@tkmsftngp10...

Patrick Molloy

unread,
Jun 25, 2002, 12:23:14 AM6/25/02
to
Under Tools/References look in the available references list for Microsoft
ActiveX Data Objects Library 2.6

Parick Molloy
Microsoft Excel MVP


"Sergio Luis Martins" <sergi...@uol.com.br> wrote in message

news:unZES7$GCHA.2904@tkmsftngp12...

0 new messages