VBA Internet Explorer iFrames Microsoft Internet Controls Microsoft HTML Object Library

vbaguy33

New Member
Joined
Feb 6, 2013
Messages
5
'I would like to go to a website that have iframes, fill out text boxes in the iframe, then click a button in the iframe

'Here is my base code that works for a website that does not have iframes
'1) open a website, fill out the building information, and Click Search
'2) Click all open Violations
'3) Search for apt 2A
'This code works for this example, but what I am trying to figure out is if the elements on page 1,2,3 are in an iFrame, how would the code change?


Public Sub IE_HPD()


'Needs references to Microsoft Internet Controls and Microsoft HTML Object Library


Dim baseURL As String
Dim IE As InternetExplorer

baseURL = "http://www.nyc.gov/html/hpd/html/home/home.shtml"

Set IE = New InternetExplorer
With IE
.Visible = True

'Navigate to the main page

.navigate baseURL
While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend

' On Page 1
.document.getElementById("p1").Value = 2 ' Burough
.document.getElementById("p2").Value = 711 ' Street Number
.document.getElementById("p3").Value = "East 231" ' Address
.document.getElementById("searchbutton").click ' Click button

While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend

' On Page 2, click All Violations Button
.document.parentWindow.execScript "__doPostBack('lbtnAllOpenViol','')"

While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend

'On Page 3 put unit 2A in the text box and click search
.document.getElementById("txtUnitNo").Value = "2A"
.document.getElementById("btnAptSearch").click


End With

Set IE = Nothing
Set shellWins = Nothing

MsgBox ("done")

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
It doesn't really, you just navigate to the actual location of the frame rather than the parent window
 
Upvote 0
Ok what if I can not navigate to that source"src". When I try to go to it, I get redirected to the page I was on.The source is aspx?
 
Upvote 0
It's difficult to help without being able to access the site itself and knowing the URL.
 
Upvote 0
My code is stuck because I am unable to get to the source link due to a redirect.

if (window == window.top) {
// Redirect to parent page if opened up by itself
top.location.replace("../ExpressSearch.aspx" + location.search);

[FONT=Consolas, Lucida Console, monospace] [/FONT][FONT=Consolas, Lucida Console, monospace]}[/FONT]

[FONT=Consolas, Lucida Console, monospace]When I go to the source link the if(window== window.top) code in the source file redirects me to the original website with all of the iframes. Therefore I can not reach the elements using my current method because I can not get to the iframe, but I can see the text boxes from the parent webpage. [/FONT]

[FONT=Consolas, Lucida Console, monospace]My questions are [/FONT]

[FONT=Consolas, Lucida Console, monospace]1) Can I manipulate iFrames text boxes while in the parent webpage
2) Is there someway I can load the source link with something above it so it does not trip the redirect
3) Is there someway for me to block the redirect

I am asking a capability question and looking for some materials to help me through this. Let me know if you have any info on VBA and iFrames
[/FONT]
 
Upvote 0
Here is some HTML base code if it helps you answer my question. I just put in the gist of it so I can see if it is possible. Let me know if this helps. Thanks

'Parent Webpage

HTML>
Head>.../Head>
Body>
Tbody>

iframe id="oIFrame" width="100%" name="oIFrame" marginwidth="0" marginheight="0" frameborder="0" src="www.sourcelink.com" style="height: 1454px;">*********>

Tbody>
/Body>
/HTML>

'Here is where what is in the iFrame source link

#document
Head>

if (window == window.top) {
// Redirect to parent page if opened up by itself
top.location.replace("../ExpressSearch.aspx" + location.search);
}

/Head>

Body>
Tbody>

input name="TextBox1" type="text" id="TextBox1" class="FormEditNumeric" size="8" csgvalidate="Integer!Range(1,99999999)!LessThanEqual('','TextBox1')" csgformat="AddCommas" csglabel="TextBox1" onchange="CSGFormatElement(this)">

input name="CheckBox1" type="checkbox" id="CheckBox1" *******="DoThis(false);" class="expressCheckbox" value="3">

/Tbody>
/Body>
/HTML>

'I need to fill in TextBox1 with text. How can I change their values?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

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