Canders_12
asked on
Excel to Internet Explorer Fun
Hello all,
I have the following code which loads up a webpage and inputs some dates into the forms which works tremendously. As you can see at the end of the code it puts focus on a button and forces a click. The result of this click is that it opens up another webpage that I would then like to manipulate in much the same way but am unable to as my VBA only looks at the original openened page. The question is:
"How can I get my VBA to transfer its attentions to the newly opened page for similar maniuplation"
Code as below which currently works perfectly :)
I have the following code which loads up a webpage and inputs some dates into the forms which works tremendously. As you can see at the end of the code it puts focus on a button and forces a click. The result of this click is that it opens up another webpage that I would then like to manipulate in much the same way but am unable to as my VBA only looks at the original openened page. The question is:
"How can I get my VBA to transfer its attentions to the newly opened page for similar maniuplation"
Code as below which currently works perfectly :)
Sub Get_DWOR_CSL_data()
Dim i As Long
Dim ie As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set ie = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
ie.Visible = True
' Maximize the window (uses function at the top of the page)
apiShowWindow ie.hwnd, SW_MAXIMIZE
' Send the form data To URL As POST binary request
ie.Navigate "http://dwor/DWOR+/Pages/ReportViewer.aspx?Rpt=rptCostedReview"
While ie.busy
DoEvents 'wait until IE is done loading page.
Wend
ie.Visible = True
'My Parameter (5093 = Days, 5094 = Eves, 5095 = Nights)
ie.Document.All("ctl00$MainContent$ddlRptParamSetID").Value = "5094"
While ie.busy
DoEvents 'wait until IE is done loading page.
Wend
ie.Document.All("ctl00$MainContent$txtDateFrom").Value = Format(Range("C3").Value, "dd/mm/yyyy")
While ie.busy
DoEvents 'wait until IE is done loading page.
Wend
ie.Document.All("ctl00$MainContent$txtDateTo").Value = Format(Range("C3").Value, "dd/mm/yyyy")
While ie.busy
DoEvents 'wait until IE is done loading page.
Wend
ie.Document.All("ctl00$MainContent$btnShowReport").Focus
ie.Document.All("ctl00$MainContent$btnShowReport").Click
'Application.Wait Now() + TimeValue("00:00:10")
End Sub
ASKER
imnorie:
Sadly it is a new window option and I have no way of amending this in internet explorer. Any further cunning ideas?
Sadly it is a new window option and I have no way of amending this in internet explorer. Any further cunning ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I appreciate the code above, however, I fall at the first hurdle:
Public IE2 As InternetExplorer
gives me an "uder-defined type not defined" compile error :/
Public IE2 As InternetExplorer
gives me an "uder-defined type not defined" compile error :/
Add a reference for Microsoft Internet Controls and Microsoft HTML Object Library.
Does Right Click and New tab work?
If so maybe you could force a RIght Click instead.
Thanks
Rob H
If so maybe you could force a RIght Click instead.
Thanks
Rob H
Rob
Is there a way to do that in code?
Is there a way to do that in code?
ASKER
robhenson:
Good shout but it is a button and right clicking gives no options :(
imnorie:
I have a meeting this morning but I will work on your solution this afternoon :)
Many thanks to you both for throwing some ideas out there.
Many thanks.
Good shout but it is a button and right clicking gives no options :(
imnorie:
I have a meeting this morning but I will work on your solution this afternoon :)
Many thanks to you both for throwing some ideas out there.
Many thanks.
ASKER
Many many thanks, Alan.
If it's a new page there's no problem, that's the the page now loaded in IE and you can refer to it just as you did the last page, which is no longer loaded in IE.