saving workbook from URL

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible to write a macro to save a workbook from URL to my c drive.

eg : i want to save a workbook from "http://...../abc.xla" to
"C:\.....\abc.xla" on a click of a button.

Suggestions will be greatly appreciated.

Thanks,
 
This was posted recently by Mudraker: (primary code from Randy Birch's site)

http://groups.google.com/[email protected]&oe=UTF-8&output=gplain.


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2003 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private 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 Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000


Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean


'Download the file. BINDF_GETNEWESTVERSION forces
'the API to download from the specified source.
'Passing 0& as dwReserved causes the locally-cached
'copy to be downloaded, if available. If the API
'returns ERROR_SUCCESS (0), DownloadFile returns True.

DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS

End Function


' Mukraker's code to call the function


Sub AutoDownloadIntranetFile()
Dim sSourceUrl As String
Dim sLocalFile As String
Dim hfile As Long


sSourceUrl = "http://www.??????"
sLocalFile = "c:\temp"
If DownloadFile(sSourceUrl, sLocalFile) = False Then
Call cmdE
MsgBox "Error In Downloading File" _
& Chr(10) _
& "Cannot Continue", vbCritical
End
End If
End Sub


sub cmdE()
AppActivate "microsoft excel"
end Sub
 

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

Back
Top