Automate "File Download" Dialog Box Without SendKeys

redbaron06

New Member
Joined
Aug 6, 2010
Messages
44
Hi All,

I was hoping that someone could help me to alternatively automate the IE File Download Dialog Box in VBA (and a second box that states the user opening a file in a different format than stated). I used SendKeys in my code below, which works, sometimes. I have searched high and low to no avail and could use some expert advice.

The code I am using navigates IE to a page, clicks on an image to export the document, and then attempts to click open and ok to open the new workbook. SaveTheData simply activates the other workbook (the new export) then saving and closing it to a specificed destination.

Thanks in advance!

Code:
    Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
 
    'Get the HTML document of the new page
 
    Set doc = IE.document
 
    max = 10000
 
    For i = 0 To max
    If doc.getElementsByTagName("img").Item(i).getAttribute("title") = "Export data in Excel" Then
    doc.getElementsByTagName("img").Item(i).Click
    Exit For
    End If
    Next
 
    [B]Application.Wait (Now + TimeValue("0:00:02"))[/B]
[B]   SendKeys "{TAB}", True[/B]
[B]   SendKeys "{TAB}", True[/B]
[B]   SendKeys "{ENTER}", True[/B]
 
    Application.Wait (Now + TimeValue("0:00:02"))
    SendKeys "{TAB}", True
    SendKeys "{TAB}", True
    SendKeys "{ENTER}", True
 
    Application.Wait (Now + TimeValue("0:00:04"))
 
    Call SaveTheFile
 
See Download web table in multiple pages for VBA code and Need help regarding IE Automation using VBA which also uses the code and discusses the techniques used. For the code to work, you must added the web site domain to IE's trusted sites, as described in the comment at the top of the code.
The code doesn't handle this box, and I've never seen such a box. If you post the URL of the page concerned I may be able to help further.
Hi John
I followed you discussion and I have a similar problem, to make the matter impossible the save windows prevent my code from execute until the end and does not reach the function File_Download_Click_Save unless the save bottom is clicked automatically below the code:
"
Sub CodeStop()Dim URL As String
Dim IeApp As Object
Dim ieDoc As Object
Dim ieForm As Object
Dim ieObj As Object
Dim objColl As Collection
Application.DisplayAlerts = False
URL = "http://www.bmreports.com/bsp/BMRSSystemData.php?pT=DDAD&zT=N&dT=NRT"


Set IeApp = CreateObject("InternetExplorer.Application")
IeApp.Visible = True
IeApp.Navigate URL


Do Until IeApp.ReadyState = READYSTATE_COMPLETE
Loop


Set ieDoc = IeApp.Document
For Each ele In IeApp.Document.getElementsByTagName("span")


If ele.innerHTML = "CSV" Then
Application.Wait (Now + TimeValue("0:00:15"))
DoEvents
ele.Click
'At this point you need to Save the document manually
' Code does not go to the next step until the save bottom is clicked



File_Download_Click_Save
End If


Next


'For i = 0 To 2
''If IeApp.Document.getElementsByTagName("span").Item(i).getAttribute("Text") = "CSV" Then
'IeApp.Document.getElementsByTagName("span").Item(i).Click
'
''Else
'Debug.Print IeApp.Document.getElementsByTagName("span").Item(i).getAttribute("Title")
''End If
'
'Next i


'Version Build = 9002379
'TAB T=1
'TAB CLOSEALLOTHERS


'URL GOTO=http://www.bmreports.com/bsp/SystemPricesHistoric.htm
'frame Name = topFrame
'TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:sysPriceForm ATTR=NAME:dT CONTENT=2013-01-01
'TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:sysPriceForm ATTR=NAME:submit
'frame Name = bottom
'TAG POS=1 TYPE=SPAN ATTR=TXT:CSV




IeApp.Quit
End Sub"

Any suggestions?

Thanks in advance
Nunzio
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top