Handling FileDownloadPopup in IE

manojsahooin

New Member
Joined
Jan 3, 2014
Messages
25
Dear Team,

I have a VBA code where it connects to web and downloads a report in excel. however the wait time to load the report is now handled using Application.Wait (Now + TimeValue("0:03:00")) but this changes every time depending on server response.

Is there a way where in, Only when FileDownloadPopup appears the rest of the code should run. please see my code below.


Sub test() 'ID7
Dim IE As Object
Dim URL As String
Dim x As String


'load internet explorer
Set IE = CreateObject("internetexplorer.application")

x = ThisWorkbook.Sheets(1).Range("B1").Value
sdate = ThisWorkbook.Sheets(1).Range("B3").Value
YA = Year(sdate)
MA = Month(sdate)
DA = Day(sdate)

EDate = ThisWorkbook.Sheets(1).Range("B4").Value
YB = Year(sdate)
MB = Month(sdate)
Db = Day(sdate)


Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
'go to website
URL = "https://xyz"

IE.navigate URL
'wait for page to load

Application.Wait (Now + TimeValue("0:03:00")) ' this is the place where i need help, currently it take approx 3 min to FileDownloadPopup

SendKeys "{TAB}", True
SendKeys "{TAB}", True
SendKeys "{TAB}", True 'for save as
SendKeys "{ENTER}", True
Application.Wait (Now + TimeValue("0:00:02"))
SendKeys "{ENTER}", True
'Workbooks.Open Filename:="C:\Users\msahoo\Desktop\test.xls"

'Application.Wait (Now + TimeValue("0:02:00"))
FileCopy "C:\Users\mk\Desktop\test.xls", "C:\Users\msahoo\Desktop\Test\me.xls"


Dim aFile As String
aFile = "C:\Users\mk\Desktop\test.xls"
If Len(Dir$(aFile)) > 0 Then
Kill aFile
End If
End Sub



Appreciate your response.

KR
MK
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,827
Messages
5,855,877
Members
431,771
Latest member
CoryMelth

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
Top