# Displaying HTML with OLE

**URL:** <https://www.ruby-forum.com/t/displaying-html-with-ole/83158>\
**Category:** Ruby\
**Created:** [January 23, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158 "2007-01-23T22:55:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [January 23, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158/1 "2007-01-23T22:55:37Z")

</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)  
OLE error code:80004005 in   
  
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

 Hello, World
# My "Hello, World" Demo

## Not much of a demo, eh?
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:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [January 24, 2007, 12:01am UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158/2 "2007-01-24T00:01:48Z")

</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:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [January 24, 2007, 1:05am UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158/3 "2007-01-24T01:05:56Z")

</div>

On Jan 23, 4:51 pm, “Richard”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> <No Description>
> 
> ```
> 
> # My "Hello, World" Demo
> ie.document.write html ie.document.close
> 
> sleep 5  
> quit

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

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [January 24, 2007, 4:55am UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158/4 "2007-01-24T04:55:21Z")

</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

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [January 26, 2007, 3:25am UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158/5 "2007-01-26T03:25:52Z")

</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

---

<div class="post-metadata">

**Author:** ![richard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f0a364/32.png) [@richard](https://www.ruby-forum.com/u/richard)\
**Post date:** [January 25, 2007, 2:45am UTC](https://www.ruby-forum.com/t/displaying-html-with-ole/83158/6 "2007-01-25T02:45:22Z")

</div>

On Jan 23, 10:50 pm, “Richard”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
