# Displaying HTML with OLE

**URL:** <https://rubytalk.org/t/displaying-html-with-ole/34740>\
**Category:** ruby-talk\
**Created:** [23 January 2007 21:55 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740 "2007-01-23T21:55:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Richard3](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Richard3](https://rubytalk.org/u/Richard3)\
**Post date:** [23 January 2007 21:55 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740/1 "2007-01-23T21:55:11Z")

</div>

Hi,

I'm running WinXP/SP2 and Ruby 1.8.2. I tried the sample below from The  
Ruby Way,2nd ed., with modified HTML (which I tested independently).  
When I run it in a Command Window, I get:

K:\_Projects\Ruby\_Ruby\_Techniques\Win32Ole\>TestingOleWithHtml.rb  
K:/\_Projects/Ruby/\_Ruby\_Techniques/Win32Ole/TestingOleWithHtml.rb:22:in  
`method\_missing': document (WIN32OLERuntimeError)  
&nbsp;&nbsp;&nbsp;&nbsp;OLE error code:80004005 in \<Unknown\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<No Description\>  
&nbsp;&nbsp;&nbsp;&nbsp;HRESULT error code:0x80020009  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exception occurred. from  
K:/\_Projects/Ruby/\_Ruby\_Techniques/Win32Ole/TestingOleWithHtml.rb:22

Any ideas?

Thanks in Advance,  
Richard

# Source: The Ruby Way, 2nd ed., pg. 585

require "win32ole"

msg = "Hello, World"

html = \<\<EOF  
\<html\>  
\<head\>  
&nbsp;&nbsp;\<title\>Hello, World\</title\>  
\</head\>  
\<body\>  
\<h1\>\<center\>My "Hello, World" Demo\</center\>\</h1\>  
\<p\>  
\<h2\>\<center\>Not much of a demo, eh?\</center\>\</h2\>  
\</body\>  
\</html\>  
EOF

ie = WIN32OLE.new("InternetExplorer.Application")

ie.document.open # \<====  
Line 22  
ie.document.write html  
ie.document.close

sleep 5  
quit

---

<div class="post-metadata">

**Author:** ![Nathan\_Smith](https://avatars.discourse-cdn.com/v4/letter/n/839c29/32.png) [@Nathan\_Smith](https://rubytalk.org/u/Nathan_Smith)\
**Post date:** [23 January 2007 23:01 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740/2 "2007-01-23T23:01:09Z")

</div>

Is your default homepage a blank page? I think this might be a problem. Set  
your default page to something else or try putting "ie.gohome" or "  
ie.navigate("[http://nlsmith.com](http://nlsmith.com)")" before the ie.document.open. Then you'll  
have a document object to work with.

Nate

---

<div class="post-metadata">

**Author:** ![David\_Mullet](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@David\_Mullet](https://rubytalk.org/u/David_Mullet)\
**Post date:** [24 January 2007 00:05 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740/3 "2007-01-24T00:05:11Z")

</div>

Try navigating to a page before writing to the Document object. The  
code below worked for me...

ie = WIN32OLE.new("InternetExplorer.Application")  
ie.Visible = 1  
ie.Navigate('about:blank')  
sleep(1) while ie.ReadyState != 4  
ie.Document.open  
ie.Document.write html  
ie.Document.close  
sleep 5  
quit

Hope that helps.

Mully

> **···**
>
> On Jan 23, 4:51 pm, "Richard" \<RichardDummyMailbox58...@USComputerGurus.com\> wrote:
> 
> > Hi,
> > 
> > I'm running WinXP/SP2 and Ruby 1.8.2. I tried the sample below from The  
> > Ruby Way,2nd ed., with modified HTML (which I tested independently).  
> > When I run it in a Command Window, I get:
> > 
> > K:\_Projects\Ruby\_Ruby\_Techniques\Win32Ole\>TestingOleWithHtml.rb  
> > K:/\_Projects/Ruby/\_Ruby\_Techniques/Win32Ole/TestingOleWithHtml.rb:22:in  
> > `method\_missing': document (WIN32OLERuntimeError)  
> > &nbsp;&nbsp;&nbsp;&nbsp;OLE error code:80004005 in \<Unknown\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<No Description\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;HRESULT error code:0x80020009  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exception occurred. from  
> > K:/\_Projects/Ruby/\_Ruby\_Techniques/Win32Ole/TestingOleWithHtml.rb:22
> > 
> > Any ideas?
> > 
> > Thanks in Advance,  
> > Richard
> > 
> > # Source: The Ruby Way, 2nd ed., pg. 585
> > 
> > require "win32ole"
> > 
> > msg = "Hello, World"
> > 
> > html = \<\<EOF  
> > \<html\>  
> > \<head\>  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\<title\>Hello, World\</title\>  
> > \</head\>  
> > \<body\>  
> > \<h1\>\<center\>My "Hello, World" Demo\</center\>\</h1\>  
> > \<p\>  
> > \<h2\>\<center\>Not much of a demo, eh?\</center\>\</h2\>  
> > \</body\>  
> > \</html\>  
> > EOF
> > 
> > ie = WIN32OLE.new("InternetExplorer.Application")
> > 
> > ie.document.open # \<====  
> > Line 22  
> > ie.document.write html  
> > ie.document.close
> > 
> > sleep 5  
> > quit

---

<div class="post-metadata">

**Author:** ![Richard3](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Richard3](https://rubytalk.org/u/Richard3)\
**Post date:** [24 January 2007 03:55 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740/4 "2007-01-24T03:55:11Z")

</div>

Hi David,

Your technique worked perfectly. I was disappointed by my system's  
performance, however.

I used a .rbw extension to avoid the creation of a temporary Command  
Window. Is there a simple approach to putting up a graphical progress  
bar that:  
-- loops while checking to see whether the IE window had opened yet;  
and  
-- closes when the IE window is displayed?

Best wishes,  
Richard

> **···**
>
> On Jan 23, 7:04 pm, "mully" \<david.mul...@gmail.com\> wrote:
> 
> > On Jan 23, 4:51 pm, "Richard" \> \> \> \> \<RichardDummyMailbox58...@USComputerGurus.com\> wrote:  
> > \> Hi,
> > 
> > \> I'm running WinXP/SP2 and Ruby 1.8.2. I tried the sample below from The  
> > \> Ruby Way,2nd ed., with modified HTML (which I tested independently).  
> > \> When I run it in a Command Window, I get:
> > 
> > \> K:\_Projects\Ruby\_Ruby\_Techniques\Win32Ole\>TestingOleWithHtml.rb  
> > \> K:/\_Projects/Ruby/\_Ruby\_Techniques/Win32Ole/TestingOleWithHtml.rb:22:in  
> > \> `method\_missing': document (WIN32OLERuntimeError)  
> > \> OLE error code:80004005 in \<Unknown\>  
> > \> \<No Description\>  
> > \> HRESULT error code:0x80020009  
> > \> Exception occurred. from  
> > \> K:/\_Projects/Ruby/\_Ruby\_Techniques/Win32Ole/TestingOleWithHtml.rb:22
> > 
> > \> Any ideas?
> > 
> > \> Thanks in Advance,  
> > \> Richard
> > 
> > \> # Source: The Ruby Way, 2nd ed., pg. 585
> > 
> > \> require "win32ole"
> > 
> > \> msg = "Hello, World"
> > 
> > \> html = \<\<EOF  
> > \> \<html\>  
> > \> \<head\>  
> > \> \<title\>Hello, World\</title\>  
> > \> \</head\>  
> > \> \<body\>  
> > \> \<h1\>\<center\>My "Hello, World" Demo\</center\>\</h1\>  
> > \> \<p\>  
> > \> \<h2\>\<center\>Not much of a demo, eh?\</center\>\</h2\>  
> > \> \</body\>  
> > \> \</html\>  
> > \> EOF
> > 
> > \> ie = WIN32OLE.new("InternetExplorer.Application")
> > 
> > \> ie.document.open # \<====  
> > \> Line 22  
> > \> ie.document.write html  
> > \> ie.document.close
> > 
> > \> sleep 5  
> > \> quitTry navigating to a page before writing to the Document object. The  
> > code below worked for me...
> > 
> > ie = WIN32OLE.new("InternetExplorer.Application")  
> > ie.Visible = 1  
> > ie.Navigate('about:blank')  
> > sleep(1) while ie.ReadyState != 4  
> > ie.Document.open  
> > ie.Document.write html  
> > ie.Document.close  
> > sleep 5  
> > quit
> > 
> > Hope that helps.
> > 
> > Mully

---

<div class="post-metadata">

**Author:** ![David\_Mullet](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@David\_Mullet](https://rubytalk.org/u/David_Mullet)\
**Post date:** [25 January 2007 01:45 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740/5 "2007-01-25T01:45:09Z")

</div>

Richard-

Try reducing the sleep interval...

sleep(1) while ie.ReadyState != 4

...to...

sleep(0.1) while ie.ReadyState != 4

Mully

> **···**
>
> On Jan 23, 10:50 pm, "Richard" \<RichardDummyMailbox58...@USComputerGurus.com\> wrote:
> 
> > Hi David,
> > 
> > Your technique worked perfectly. I was disappointed by my system's  
> > performance, however.

---

<div class="post-metadata">

**Author:** ![Richard3](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@Richard3](https://rubytalk.org/u/Richard3)\
**Post date:** [26 January 2007 02:25 UTC](https://rubytalk.org/t/displaying-html-with-ole/34740/6 "2007-01-26T02:25:05Z")

</div>

Hi David,

> Try reducing the sleep interval...
> 
> sleep(1) while ie.ReadyState != 4

That sped it up a lot. Of course, a couple of test runs doesn't prove  
much, e.g. my virus checker might have been running unattended in  
background yesterday.

Nevertheless, this is a useful technique for me.

Again, many thanks.  
Richard

> **···**
>
> On Jan 24, 8:42 pm, "mully" \<david.mul...@gmail.com\> wrote:
> 
> > On Jan 23, 10:50 pm, "Richard" \> \> \<RichardDummyMailbox58...@USComputerGurus.com\> wrote:  
> > \> Hi David,
> > 
> > \> Your technique worked perfectly. I was disappointed by my system's  
> > \> performance, however.Richard-
> > 
> > Try reducing the sleep interval...
> > 
> > sleep(1) while ie.ReadyState != 4
> > 
> > ...to...
> > 
> > sleep(0.1) while ie.ReadyState != 4
> > 
> > Mully
