Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Internet Explorer Object | Pop up Window

This is a discussion on Internet Explorer Object | Pop up Window within the Excel Questions forums, part of the Question Forums category; Hello, I have a VBA project that navigates to a website and then clicks on a link. When I click ...

  1. #1
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Internet Explorer Object | Pop up Window

    Hello,

    I have a VBA project that navigates to a website and then clicks on a link. When I click the link in my code a new IE Browser opens with a form that I wan to fill out. I know how to update the form, but I don't know how to reference the new browser window that was opened when I clicked on the link.

    Here is some of my code:

    Code:
    'Open End User Multiple Selection
    Set tags = myIE.document.getElementsByTagName("A")
    For Each tag In tags
        If InStr(1, tag, "'multiple_selections.htm','EndUser'", vbTextCompare) > 0 Then
            tag.Click
            Exit For
        End If
    Next
    when I try to reference the document in the popup window, it is still referencing the previous window. How can I set my "myIE" object to reference the new pop up window?

    Thanks in advance for your help.

  2. #2
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Internet Explorer | Open Window

    Hello,

    I posted a similar message to this not long ago, but I didn't receive any responses. I hoped by restating my problem and giving more detail, somebody might have an idea.

    Currently I have a list in excel that I want to populate in an Internet Explorer Form. I have already coded into my macro the ability to open internet explorer, logon to the website where the form is located. Once on the website, I need to click a link that opens a new browser window where the form is. Unfortumately my internet explorer object still references the other open window that contains the link that opens the browser form. How do I create a new Internet Explorer object that will reference the pop up object browser. Here is a snippet of my code to date:

    Code:
    'Variable declarations
    Dim myIE As New InternetExplorer 'New '
    Dim myURL As String
    Dim myDoc As HTMLDocument
    
    myURL = "https://..."
    
    
    myIE.navigate myURL
    myIE.Visible = True
    
    Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
    
    Set myDoc = myIE.document
    
    myDoc.forms(1).loginid.Value = userName
    myDoc.forms(1).password.Value = password
    myDoc.form1.submit
    
    Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
    
    'Open End User Multiple Selection
    Set tags = myIE.document.getElementsByTagName("A")
    For Each tag In tags
        If InStr(1, tag, "'multiple_selections.htm','EndUser'", vbTextCompare) > 0 Then
            tag.Click
            Exit For
        End If
    Next

    The problem happens after the last for loop because the variable "myIE" still references the old web page with the link that I just clicked to open the form. I need to now create an object that references that new form and I can't figure how to do it.

    Thanks in advance for your help.

  3. #3
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling
    Posts
    64,939

    Default Re: Internet Explorer | Open Window

    Must you click the link and open a new browser?

    Why don't you just navigate to it, just as you navigated to the original URL?

    You should be able to extract the relevant URL from the relevant tag.
    If posting code please use code tags.

  4. #4
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Re: Internet Explorer Object | Pop up Window

    Because after I open the form, there is a submit button that takes me back to the previous page. If I try to navigate to the URL the form displays in Internet Explorer, but then when I click the submit button, it doesn't take me back to the previous page which I need to be on to take further action. Instead, after you press the submit button the previous page does not load and says there was an error.

  5. #5
    Board Regular Norie's Avatar
    Join Date
    Apr 2004
    Location
    Stirling
    Posts
    64,939

    Default Re: Internet Explorer Object | Pop up Window

    I'm afraid I don't quite understand what you mean.

    If you have the relevant URLs then you should be able to navigate wherever you want.

    Mind you if you are dealing with a secure site that you need to log into you might need to do that multiple times.

    By the way you really shouldn't need to use click, if what you are submitting is a form then use it's submit method.
    If posting code please use code tags.

  6. #6
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Re: Internet Explorer Object | Pop up Window

    I'm aware of that. But when you submit the form, it actually just stores the information. After you have submitted the form, you then need to choose more options on the previous page. Once all this is done, you submit that page and it uses the information in that form to do some processing of the data.

    Do you know of any way to reference an Internet Explorer window that is already open without navigating to it? That would actually solve my problem completely.

  7. #7
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Re: Internet Explorer Object | Pop up Window

    Oh. So another reason why you can't navigate to it is because the URL tracks some sort of session variable inside it. So if you navigate separately to the form, the session of that form is not tracked by the browser that needs the information from the form. Any other ideas?

  8. #8
    Board Regular
    Join Date
    Oct 2007
    Posts
    2,819

    Default Re: Internet Explorer Object | Pop up Window

    Here are 2 possible methods:

    1. Loop through ShellWindows, looking for your particular IE window, e.g. by its window title or URL. For example code see Navigate to Webpage based on IF.

    2. Better still, use InternetExplorer WithEvents to capture the creation of the IE child window via the NewWindow2 event. See my post at VBA Automation of Internet Explorer Child Window for example code.

  9. #9
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Re: Internet Explorer Object | Pop up Window Control - Solution

    Ok, well thanks to some diligent searching on the internet, I found a solution to the problem. If you are ever using Excel VBA to click on a link and it opens a pop-up window, your internet explorer object will continue to reference the parent browser and not the child browser. I found this code on another site to help you create an object that will allow you to manipulate the child or pop-up browser:

    Code:
    Dim objSW As ShellWindows
    Dim objIE As InternetExplorer
    
    Set objSW = New ShellWindows
    For Each x In objSW
            If x.LocationName = "Multiple Selection" Then
                Set objIE = x
                Exit For
            End If
    Next x
    The ojSW will contain all of the open windows on your computer (as objects of course). You can iterate through each one of them until you find the "LocationName" of the window that you are interested in. Once you find it, set your new IE variable equal to that object and you can keep playing with it.

    Thanks for your help.

  10. #10
    Board Regular
    Join Date
    Mar 2006
    Posts
    94

    Default Re: Internet Explorer Object | Pop up Window

    Hi John,

    Thanks for your reply. I'm really interested in learning more about WithEvents. I tried to implement the code in VBA Automation of Internet Explorer Child Window. When I tried to add the following line of code to a regular module I received the following error: "only valid in object module".

    Code:
    Public WithEvents IE1 As InternetExplorer
    Does this code have to be implemented in a Class module or is there a workaround?

Page 1 of 2 12 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com