Internet Explorer Automation

rwhitmore90

New Member
Joined
Mar 6, 2014
Messages
4
I have a few questions regarding internet explorer automation. I am using Excel 2010. I am trying to automate an internal web application. Unfortunately the web application from what I can tell is a series of java script functions. I would post the source code but for obvious reasons I am not allowed. Once you log in the URL never changes. I have set up my macro to look for the already open window. Once it does I want it to fill in a form. The macro for selecting the appropriate window works. The form is located in a table which is in an iframe. How can I input values into the form?

Code:
Option Explicit
' Arguments:
'   Title     -  title of the searchied IE window
'   [IsLike]  -  False/True = exact/partial searching, default is False
'   [IsFocus] -  False/True = don't_activate/activate IE window, default is False
Function GetIeByTitle(Title, Optional IsLike As Boolean, Optional IsFocus As Boolean) As Object
  Dim w As Object
  For Each w In CreateObject("Shell.Application").Windows
    With w
      If .Name = "Windows Internet Explorer" Then
        If IsLike Then
          If InStr(1, .LocationName, Title, vbTextCompare) > 0 Then
            If IsFocus Then
              w.Visible = False
              w.Visible = True
            End If
            Set GetIeByTitle = w
            Exit For
          End If
        Else
          If StrComp(.LocationName & " - " & .Name, Title, 1) = 0 Then
            If IsFocus Then
              w.Visible = False
              w.Visible = True
            End If
            Set GetIeByTitle = w
            Exit For
          End If
        End If
      End If
    End With
  Next
  Set w = Nothing
End Function
 

Sub Test_GetIeByTitle()
  Dim IE As InternetExplorer
  Dim Title As String
  Dim frm As Variant
  Dim frame As Variant


  
  Title = "Withheld"
  Set IE = GetIeByTitle(Title, True, True)
  If IE Is Nothing Then
    MsgBox "IE window with this Title is not found:" & vbLf & """" & Title & """", 48
  Else
    Set frame = IE.Document.getElementById("contentFrame")
    
    Set frm = frame.Document.getElementById("frm1")
    If inputForm Is Nothing Then
        MsgBox "No form"
    End If
  End If
End Sub

I have been messing around with the code a lot. I have tested whether it is finding the frame and it is. After that, I don't know how to work within the form that is located in a table. Any help would be greatly appreciated. Thank you!
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Once you have a reference to the form (the frm variable in your code), you can reference a form field using any of these depending on exactly how the HTML is designed:
Code:
frm.getElementsByTagName("INPUT")(0).value = "text box value"  'assumes first INPUT tag is a text box
frm.getElementsByName("fieldName")(0).value = "123"  'populates 1st input field which has name="fieldName"
frm.elements("fieldName").value = "xyz" 'populates input field which has name="fieldName"
there are other ways too, but the above should get you started.
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,660
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top