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
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
>.
>
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...
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...
Regards,
Sergio
"dermot" <dermotbalso...@hotmail.com> escreveu na mensagem
news:10b6401c218b6$0b694cc0$9be62ecf@tkmsftngxa03...
Regards,
Sergio Luis
"Jake Marx" <ja...@longhead.com> escreveu na mensagem
news:uu1dK1OGCHA.2312@tkmsftngp12...
Regards,
Sergio Luis
"Ron de Bruin" <ronde...@kabelfoon.nl> escreveu na mensagem
news:uaVFzGTGCHA.1288@tkmsftngp10...
Parick Molloy
Microsoft Excel MVP
"Sergio Luis Martins" <sergi...@uol.com.br> wrote in message
news:unZES7$GCHA.2904@tkmsftngp12...