Unable to refresh iFrame using VBA

shanwei96

New Member
Joined
Sep 6, 2015
Messages
1
I'm trying to use VBA to automatically post adverts on this website called Gumtree. I've been successful with getting VBA to fill up the HTML form input fields but am now stuck at getting the description box iframe to register the new outerHTML.

Here is the website: Gumtree Post

This is the procedure of posting:


  1. Under "Choose a location", select any random location
  2. Under "Choose a category", select Jobs > Part-Time Jobs > Other Part-Time Jobs
  3. Under "Information of the ad", I am stuck at filling up the Description Box

The Description Box is an iFrame embedded in the HTML Document. Before filling in anything, this is the HTML code of the iFrame:

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"><!--</font-->DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv="content-type" content="text/html; charset=UTF-8">
<STYLE>body {background:#FFFFFF;margin:0px;padding:0px;text-align:left;font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size:0.875em;}.desc{color:gray;} body.error{ background-color:#EFDBD6;} body.valid { background-color:#F0FFC1; color :#468847;} P {margin-top:0;margin-bottom:0}a{text-decoration: none;color:#000}<!--</font-->STYLE>
<!--</font-->HEAD>
<BODY id="rte">
<P class="desc"><!--</font-->P><!--</font-->BODY><!--</font-->HTML>
</code>

Manually keying in words into the description box gives a new html of: (Note the body tag with an additional attribute of class="valid" that makes the iframe accept the input:

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"><!--</font-->DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv="content-type" content="text/html; charset=UTF-8">
<STYLE>body {background:#FFFFFF;margin:0px;padding:0px;text-align:left;font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size:0.875em;}.desc{color:gray;} body.error{ background-color:#EFDBD6;} body.valid { background-color:#F0FFC1; color :#468847;} P {margin-top:0;margin-bottom:0}a{text-decoration: none;color:#000}<!--</font-->STYLE>
<!--</font-->HEAD>
<BODY class="valid" id="rte">
<P>I typed this manually!<BR><!--</font-->P><!--</font-->BODY><!--</font-->HTML>

</code>This is what I've tried to do to fill in the description box using VBA:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">IE.Document.getElementsByTagName("iframe")(0).contentDocument.getElementsByTagName("body")(0).innerHTML ="This is posted using VBA.
"
</code>And this as well:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;">IE.Document.getElementsByTagName("iframe")(0).contentDocument.getElementsByTagName("body")(0).outerHTML ="This is not working too!
</code>
So this is what my VBA can achieve using both codes:

<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; white-space: inherit;"><!--</font-->DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv="content-type" content="text/html; charset=UTF-8">
<STYLE>body {background:#FFFFFF;margin:0px;padding:0px;text-align:left;font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size:0.875em;}.desc{color:gray;} body.error{ background-color:#EFDBD6;} body.valid { background-color:#F0FFC1; color :#468847;} P {margin-top:0;margin-bottom:0}a{text-decoration: none;color:#000}<!--</font-->STYLE>
<!--</font-->HEAD>
<BODY class="error" id="rte">
<P>VBA cannot fill this in without error!<BR><!--</font-->P><!--</font-->BODY><!--</font-->HTML>

</code>I noticed that the important thing I need to achieve is getting the body tag to include this new attributeclass="valid" so that there would be no error. Yet even after manually editing it to class="valid" I still get class="error" instead and I am thus unable to proceed.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,216,106
Messages
6,128,863
Members
449,473
Latest member
soumyahalder4

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