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