# Why this script doesn't work?

**URL:** <https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219>\
**Category:** Ruby\
**Created:** [December 4, 2006, 5:35am UTC](https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219 "2006-12-04T05:35:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 4, 2006, 5:35am UTC](https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219/1 "2006-12-04T05:35:09Z")

</div>

Hi all,

I copy a script from WIN32OLE documentation and run it. I find that Ruby  
complains it at line cells = sheets.cells(“A1:A5”).

Do I miss something?

Thanks,

Li

## 

require ‘win32ole’

excel = WIN32OLE.new(‘Excel.Application’)  
excel.Visible=“True”

book = excel.workbooks.add  
sheets = book.worksheets(1)

cells = sheets.cells(“A1:A5”)

cells.each do |row|  
row.value = 10  
end

##output

> ruby test3.rb  
> test3.rb:13:in `method\_missing’: cells (WIN32OLERuntimeError)  
> OLE error code:80020005 in   
>   
> HRESULT error code:0x80020009  
> Exception occurred. from test3.rb:13  
> Exit code: 1

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 4, 2006, 8:50am UTC](https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219/2 "2006-12-04T08:50:33Z")

</div>

Li Chen wrote:

> Hi all,
> 
> I copy a script from WIN32OLE documentation

Where is the Win32OLE documentation located, please? That way, others  
can  
confirm your effort and duplicate your experiment (if they are running  
Windows).

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 4, 2006, 9:16am UTC](https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219/3 "2006-12-04T09:16:37Z")

</div>

here are some win32ole doc:

[http://www.ruby-doc.org/stdlib/libdoc/win32ole/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/win32ole/rdoc/index.html)

[http://www.ruby-doc.org/stdlib](http://www.ruby-doc.org/stdlib)

2006/12/4, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 4, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219/4 "2006-12-04T14:21:13Z")

</div>

Li Chen wrote:  
…

> cells = sheets.cells(“A1:A5”)

Try:  
cells = sheets.Range(“A1:A5”)

Cheers  
Chris

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [December 4, 2006, 10:34am UTC](https://www.ruby-forum.com/t/why-this-script-doesnt-work/78219/5 "2006-12-04T10:34:08Z")

</div>

Paul L. wrote:

> Where is the Win32OLE documentation located, please? That way, others  
> can  
> confirm your effort and duplicate your experiment (if they are running  
> Windows).

It is here

[http://www.ruby-doc.org/stdlib/](http://www.ruby-doc.org/stdlib/)

WIN32OLE#each{|i|…} or each(WIN32OLE)in Methods section

Iterates over each item of OLE collection which has IEnumVARIANT  
interface.

excel = WIN32OLE.new(‘Excel.Application’)  
book = excel.workbooks.add  
sheets = book.worksheets(1)  
cells = sheets.cells(“A1:A5”)  
cells.each do |cell|  
cell.value = 10  
end

Li
