Microsoft Excel - VBA Download Files from website and save them in local without manual intervention

Asked By Rajender Prasad on 06-Jun-13 11:06 AM

Dear All,

I have a button in a website to download textfile, and Once I click on it, I will get a save as dialogue box to save the file. I know how to click on button but I need your help in handling the save as dialogue box.. there should not be any manual intervention in this process/

Thanks in advance.

Prasad

Harry Boughen replied to Rajender Prasad on 06-Jun-13 07:56 PM
Hello Prasad,
When you say you want to handle the Save As dialog box does that include setting the file name and if so what is the basis for determining the file name?
If the file already has a name the something simple like:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Me.Save
End Sub

This has the be entered in the code for ThisWorkbook
Regards
Harry
Sathish S replied to Rajender Prasad on 07-Jun-13 05:19 AM

Could try this API Call

Public 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
Sub DownloadFile(URL As String, SaveAsFile As String)
Dim b
b = URLDownloadToFile(0, URL, SaveAsFile, 0, 0)
End Sub