Internet Explorer w/ iframes Automation Macro

kboy1289

New Member
Joined
Nov 14, 2012
Messages
12
hi all,
I’m trying to figure out how to have a macro bring up a website (an internal document website) locate the correct frame uncheck a box, fill in a field with a cell value (from A2) click submit, jump to the next frame within the same website and click a link. my main problem is it looks as though there are nested frames and iframes which im not familiar with. since the website is internal and you wont be able to access it, i have taken snips of the website itself, along with snips of the html and posted them to photobucket. http://s667.beta.photobucket.com/user/kboy1289/library/</SPAN></SPAN>
if you look at the snip of the website the fields i need to be referenced or filled are...

in the frame "frameSearchCriteria" (which i believe is itself within an iframe)
"My Loans Only" box unchecked (html name is "xMyContainers")
"Loan Number" field filled with cell A2 (html name is "xObjectSearchValue")
"Search" button clicked (html ID is "xSearchSubmit")
after these steps have been taken it would then jump to the next frame "frameSearchResults"
and would click the row (html name is "xRowClickAction")

i realize this would be difficult without access to the site, however the posted html and a snip of the website should help. heres two versions of code i have so far, any help is greatly appreciated! thanks!

Code:
Public Sub IE_Automation()
    Dim baseURL As String
    Dim IE As InternetExplorer
    Dim HTMLDoc As HTMLDocument
    Dim mainFrame As HTMLIFrame
    Dim slotsDiv As HTMLDivElement
    Dim frmCol As FramesCollection
    Dim htmlColl As Object
    Dim htmlInput As Object
    
    baseURL = "[URL]http://imaging/xsuite/xapps/default.aspx[/URL]"
    
    Set IE = New InternetExplorer
    With IE
        .Visible = True
        
        'Navigate to the main page
        
        .Navigate baseURL & ""
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
       
        'Get the mainFrame iframe and navigate to it
    
        Set mainFrame = .document.getElementById("xProjectFrame1_Panel")
        .Navigate baseURL & mainFrame
        While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        
    Set frmCol = IE.document.Frames 'Get the frame collection
    Set HTMLDoc = frmCol.Item(1).document 'Get the HTML document within the frame
    Set htmlColl = HTMLDoc.getElementsByName("xMyContainers") 'Get the input collection from this HTML doc
    For Each htmlInput In htmlColl
        If htmlInput.Name = "xMyContainers" Then htmlInput.Value = ("0")
    Next htmlInput
    Set htmlColl = HTMLDoc.getElementsByName("xObjectSearchValue") 'Get the input collection from this HTML doc
    For Each htmlInput In htmlColl
        If htmlInput.Name = "xObjectSearchValue" Then htmlInput.Value = ("4213010634")
    Next htmlInput
    
    Do While IE.Busy: DoEvents: Loop
    Do While IE.readyState <> 4: DoEvents: Loop

    Set IE = Nothing
    End With
    
    
End Sub

Code:
Sub Xdoc()
   
    Dim oIE As InternetExplorer
    Dim HTMLDoc As HTMLDocument
    Dim frmCol As FramesCollection
    Dim HTMLFrame As HTMLDocument
    Dim htmlColl As Object
    Dim htmlInput As Object
    
    
    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.Navigate ("[URL]http://imaging/xsuite/xapps/default.aspx[/URL]")
    
    Do While oIE.Busy: DoEvents: Loop
    Do While oIE.readyState <> 4: DoEvents: Loop
    
    oIE.Visible = True
     ' Go through <FRAME>to get to main document
    Set frmCol = oIE.document.Frames 'Get the frame collection
    Set HTMLFrame = frmCol.Item(2).document 'Get the HTML document within the frame
    Set htmlColl = HTMLDoc.getElementsByName("xMyContainers") 'Get the input collection from this HTML doc
    For Each htmlInput In htmlColl
        If htmlInput.Name = "xMyContainers" Then htmlInput.Value = ("0")
    Next htmlInput
    Set htmlColl = HTMLDoc.getElementsByName("xObjectSearchValue") 'Get the input collection from this HTML doc
    For Each htmlInput In htmlColl
        If htmlInput.Name = "xObjectSearchValue" Then htmlInput.Value = ("4213010634")
    Next htmlInput
    Set htmlColl = HTMLDoc.getElementsByName("Search") 'Get the input collection from this HTML doc
    For Each htmlInput In htmlColl
        If htmlInput.Name = "Search" Then htmlInput.Click
    Next htmlInput
        
     Do While oIE.Busy: DoEvents: Loop
    Do While oIE.readyState <> 4: DoEvents: Loop

    Set oIE = Nothing
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Where exactly are you getting stuck? Your approach seems right, frames are just documents in documents - think of them as windows to another page each is a page in it's own right, so you can go as deeply as required - so getting a frame in a frame is no different from getting the first set of frames - the below is perfectly legitimate:

Code:
Sub test()
Dim oIE As InternetExplorer: Set oIE = New InternetExplorer
Dim oDocument As HTMLDocument
Dim oDocument2 As HTMLDocument
Dim Frames As FramesCollection
Dim Frames2 As FramesCollection




oIE.Navigate "Somewhere"
Do While oIE.Busy: DoEvents: Loop
Do While oIE.ReadyState <> 4: DoEvents: Loop




With oDocument
   Set Frames = oIE.Document.Frames 'Frames on directed Page
   Set oDocument = Frames(1).Document 'Document of Frame in directed page
   Set Frames2 = oDocument.Frames ' Frames collection within above page (so 1 level deeper)
   Set oDocument2 = Frames2(0).Document ' Document within the above frame
End With








End Sub

You can always check the location of the frame you're in by grabbing the url of the document contained - frames are just windows, they don't really have properties of their own, you need to read the document they contain. For example:

Code:
Sub test()
Dim oIE As InternetExplorer: Set oIE = New InternetExplorer
Dim oDocument As HTMLDocument
Dim Frames As FramesCollection
Dim x As Long


oIE.Navigate "Somewhere"


Do While oIE.ReadyState <> 4: DoEvents: Loop


Set Frames = oIE.Document.Frames


For x = 0 To Frames.Length - 1
    Debug.Print Frames(x).Document.URL
Next x




End Sub

I'm afraid I can't actually read any of the pictures you posted, they're too small and blurry
 
Upvote 0
kyle,
thanks for the response. i do have a couple questions for you. the html shows iframes, would that make any difference in how to reference a particular frame? in other words, would they both use the same "frame" reference type? also is there a way to reference a frame by name? so say the name of the frame i'm looking for is "frameSearchCriteria" would there be a way to have it look through the collection of frames for that specific frame name? i appreciate the help, i'll give this a shot tomorrow at work, unfortunately i cant get to the website from home. i'll also try to copy some clear and legible HTML if i'm still having trouble.
 
Upvote 0
I suspect not, but why not try it?

also is there a way to reference a frame by name? so say the name of the frame i'm looking for is "frameSearchCriteria" would there be a way to have it look through the collection of frames for that specific frame name

You're already using the .getElementsByName method, so I'm not really sure what you're asking here - Doesn't it work? My preference would be to loop through and check the location of the document within the frame (as per my code above), this is probably less likely to change than the name of the frame.
 
Upvote 0
kyle,
to clairfy what i was asking above, i was wondering if it would search the main page (that houses all frames) for a particular frame name and navigate to it. my understanding of frames is very limited so i thank you for your patience. however i've since changed the link to what i believe to be the correct frame (so the URL should go directly to the frame that houses the frame i'm looking for) and searches that main frame for the nesting frame. but now when i run it, nothing happens. i dont think its getting to the field just yet, but i think it's on the right frame. would having a form on the frame change anything? i've never worked with them before. the forms name is "xForm" so i'm wondering if i have to somehow reference that before i can reference the particular field i'm searching for. here's the updated code
Code:
Sub test()
Dim oIE As InternetExplorer
Dim oDocument As HTMLDocument
Dim oDocument2 As HTMLDocument
Dim Frames As FramesCollection
Dim Frames2 As FramesCollection
Dim htmlColl As Object
Dim htmlInput As Object
Dim HTMLDoc As HTMLDocument
    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.Navigate ("[URL]http://imaging/zapp/xapps/mtg/axSearchDashboard.aspx?xToolId=SEARCHDASHBOARD&xProjectId=1000&xExcludeLinks=1&xIsInline=1&xRowClickAction[/URL]=&")
    
    Do While oIE.Busy: DoEvents: Loop
    Do While oIE.readyState <> 4: DoEvents: Loop
    oIE.Visible = True
With oDocument
   Set Frames = oIE.document.Frames 'Frames on directed Page
   Set oDocument = Frames.Item(1).document 'Document of Frame in directed page
    Set htmlColl = oDocument.getElementsByName("xObjectSearchValue") 'Get the input collection from this HTML doc
    For Each htmlInput In htmlColl
        If htmlInput.Name = "xObjectSearchValue" Then htmlInput.Value = ("4212080163")
    Next htmlInput
    End With
End Sub
 
Last edited:
Upvote 0
after some tinkering i've gotten it to work, just one last favor to ask. nowhere in the html do i see a "name" reference to a search button. nor a tag name. only value, class and id. anyway to search for those? (getElementsByID?)
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,403
Members
452,325
Latest member
BlahQz

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