locked
handle to new IE window and populate fields of webpage RRS feed

  • Question

  • Hi,

     I want to automate a process using an excel macro. I manually fill in fields of a webpage. most of the fields are static, so I want to create a macro that could fill the values for me automatically.

    There multiple pages involved here.

    The first page has a link reading "Create Request". On clicking this link, it opens up a new IE window with all the fields empty and these fields need to be populated by data in VBA code variables.

     

    I achieved the process of opening this form by using the document object. Code synopsis of VBA is as follows:

     

    IEhandle2.Navigate URL2

    Set IEdoc1 = IEhandle2.Document

     

    For i = 1 To IEdoc1.links.Length
      If Trim(IEdoc1.links(i - 1).innertext) = "Create Request" Then
             IEdoc1.links(i - 1).Click

      End If
    Next i

    But once the new webpage opens, I lose handle to that new page. And since I have lost access to the new window, cannot get access to the fields that I want to populate.

    My questions are :

    (a) How can I get a handle to the new window that came up after I performed the click. Note, I cannot use the new page address directly as a part of Navigate2 function, because few contents of the resultant webpage vary for both cases.

     

    (b) I tried the Navigate2 option to just to see the fields of the webpage that I want to populate.

    The problem is that even though there are many text fields on the webpage, none of them listed when I tried the following command :

    Debug.Print i, Mid(IEdoc3.links(i - 1).innertext, 1, 20), TypeName(IEdoc3.links(i - 1)), IEdoc3.links(i - 1).innerHTML

    It gave me all the buttons, drop downs, but no text fields.

    Any suggestions, how could I get access to the text fields on the webpage, so that I can populate the values of VBA variables to the individual text boxes.

     

    I cannot use anyother programming language to get this done. VBA only.

    Any inputs would be helpful to proceed in getting this automation done.

     

    Thanks

    SJ

     

    Friday, February 1, 2008 2:31 AM

All replies

  • Same problem. I would like to retrieve information from the new IE window. I dont know how can I refer to this new window.

    I tried to use 

     

    AppActivate "NewIE"  

    Set myIE = ActiveWindow

     

    to make a reference. But unluckily, myIE will be only a "window" object. I cannot retrieve the htmlElement from myIE

     

     

    Winston

     

    Friday, February 29, 2008 10:16 AM
  • Hi,

     After a lot of research, I ended up with this and it help me get the required handle.

     

    This is specific to VBA.

    Dim IEhandle3 As InternetExplorer

    Set IEhandle3 = CreateObject("InternetExplorer.Application")


    Private Sub get_IE_handle()
    Dim mywinie As Object
    Set mywinie = CreateObject("Shell.application")
    Dim allwindows As Object
    Set allwindows = mywinie.Windows


    For Each myie3 In allwindows
    '  Debug.Print myie3.LocationURL
      If myie3.LocationURL = CRURL Then     ' check for IE that has the required URL
        Exit For
      End If
    Next

    Set IEhandle3 = myie3

    End Sub

    Saturday, March 1, 2008 11:05 PM
  • Thank you SJ. My problem solved. I think there can be a simpler way. Maybe we can use the newWindow2 event handler. But I am just a new VB user. I cannot even compile my code, a lot of syntax error.

     

    Anyway, thank you for your advise.

     

    Winston

     

    Thursday, March 6, 2008 3:44 AM
  • Hi,

    I want to get the handle for internet explorer window opened using shellexecute function.
    Could you please give me some information how to get the handle in VC++ ?
    Thursday, August 6, 2009 8:36 AM