Link to home
Start Free TrialLog in
Avatar of Canders_12
Canders_12Flag for United Kingdom of Great Britain and Northern Ireland

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

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

Open in new window

Avatar of Norie
Norie

Is it a new page or a new window?

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.

Avatar of Canders_12

ASKER

imnorie:

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
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :/
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
Rob

Is there a way to do that in code?
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.
Many many thanks, Alan.