Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default download a file from a webpage with VBA

How do I download a file from a webpage with VBA?
I know how to open a hyperlink with the FollowHyperlink function, but I
can't find any information about how to download a file to a specified
folder.
The idea is to automatically update an Excel add-in from a webpage.
Thanks for any advice.

RBS

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 575
Default download a file from a webpage with VBA

RB,

You'll need to know the ip address of the source machine and change the
strFullURL line.

Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal strURL As String, _
ByVal strFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Public Sub GetInternetFile(strFileName As String)

Dim lReturn As Long
Dim strFullURL As String
Dim strLocation as string

strFullURL = "http:\\nnn.nnn.nnn.nnn\subfolder\" & strFileName
strLocation = environ("Temp") & "\" & strFileName

lReturn = URLDownloadToFile(0, strFullURL, strLocation, 0, 0)

If lReturn < 0 Then call msgbox("failed")

End Sub

Robin Hammond
www.enhanceddatasystems.com

"RB Smissaert" wrote in message
...
How do I download a file from a webpage with VBA?
I know how to open a hyperlink with the FollowHyperlink function, but I
can't find any information about how to download a file to a specified
folder.
The idea is to automatically update an Excel add-in from a webpage.
Thanks for any advice.

RBS



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default download a file from a webpage with VBA

RB

I found this code sometime ago and I use it almost daily to download a
text file





'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''
' 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



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


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


---
Message posted from http://www.ExcelForum.com/

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default download a file from a webpage with VBA

Robin, Mudraker,

Thanks for the code.
I haven't got it working yet, but that is because I have some trouble
figuring out the right
URL of the download link.
MudRaker, what is the line Call cmdE doing?

RBS


"RB Smissaert" wrote in message
...
How do I download a file from a webpage with VBA?
I know how to open a hyperlink with the FollowHyperlink function, but I
can't find any information about how to download a file to a specified
folder.
The idea is to automatically update an Excel add-in from a webpage.
Thanks for any advice.

RBS


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default download a file from a webpage with VBA

All fixed now. It works very smooth indeed. Thanks for the code.

RBS


"RB Smissaert" wrote in message
...
How do I download a file from a webpage with VBA?
I know how to open a hyperlink with the FollowHyperlink function, but I
can't find any information about how to download a file to a specified
folder.
The idea is to automatically update an Excel add-in from a webpage.
Thanks for any advice.

RBS




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default download a file from a webpage with VBA

RB

a moudule that used to do more but now only has one command in it

sub cmdE
AppActivate "microsoft excel"
end eu

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Insert Excel file into webpage EagerGit Excel Discussion (Misc queries) 0 April 13th 10 10:27 AM
download file of 200 name, addr.etc to excel file - how? please ad Tony V. Excel Worksheet Functions 1 October 24th 08 09:50 AM
Saving an file with charts as a webpage - border problem Sarah Excel Discussion (Misc queries) 0 June 28th 06 01:27 PM
I need to download an exel spreadsheet file. (file extension :xls) buckrogers Excel Discussion (Misc queries) 2 December 8th 04 11:08 PM
using vba to download file via ftp daryl Excel Programming 3 January 29th 04 07:58 AM


All times are GMT +1. The time now is 06:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"