# Fetch an excel sheet name in ruby

**URL:** <https://www.ruby-forum.com/t/fetch-an-excel-sheet-name-in-ruby/161221>\
**Category:** Ruby\
**Created:** [February 24, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/fetch-an-excel-sheet-name-in-ruby/161221 "2009-02-24T13:00:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![deeparaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85f322/32.png) [@deeparaj](https://www.ruby-forum.com/u/deeparaj)\
**Post date:** [February 24, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/fetch-an-excel-sheet-name-in-ruby/161221/1 "2009-02-24T13:00:15Z")

</div>

hi,  
I got this error.in `method\_missing’: Open (WIN32OLERuntimeError)  
OLE error code:800A03EC in Microsoft Office Excel

For the below coding:

require ‘win32ole’  
require ‘rubygems’

xl = WIN32OLE.new(‘Excel.Application’)  
wb = xl.Workbooks.Open(“C:\Documents and  
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)”)  
ws = wb.Worksheets(1)  
puts ws.Name  
wb.Close  
xl.Quit

---

<div class="post-metadata">

**Author:** ![deeparaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85f322/32.png) [@deeparaj](https://www.ruby-forum.com/u/deeparaj)\
**Post date:** [February 24, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/fetch-an-excel-sheet-name-in-ruby/161221/2 "2009-02-24T14:24:07Z")

</div>

Deepa R. wrote:

> hi,  
> I got this error.in `method\_missing’: Open (WIN32OLERuntimeError)  
> OLE error code:800A03EC in Microsoft Office Excel

Escape (double-up) your backslashes in double quotes, or place your  
filepath in single quotes.

Change this:

wb = xl.Workbooks.Open(“C:\Documents and  
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)”)

To this:

wb = xl.Workbooks.Open(“C:\Documents and  
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)”)

Or this:

wb = xl.Workbooks.Open(‘C:\Documents and  
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)’)

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com/)**
>
> On using the Ruby programming language on the Microsoft Windows platform

> **[Ruby on Windows](http://rubyonwindows.blogspot.com/search/label/excel)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![deeparaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85f322/32.png) [@deeparaj](https://www.ruby-forum.com/u/deeparaj)\
**Post date:** [February 25, 2009, 10:44am UTC](https://www.ruby-forum.com/t/fetch-an-excel-sheet-name-in-ruby/161221/3 "2009-02-25T10:44:18Z")

</div>

hi,  
It works only in windows what i have to do for working in both linux  
and window environment

require ‘win32ole’  
require ‘rubygems’  
excel = WIN32OLE.new(“excel.application”)  
excel.visible =false  
workbook = excel.workbooks.open(“E:\Book1.xls”)  
tt=workbook.Worksheets.count  
puts “Number of Worksheets”  
puts tt.to\_i  
puts “Randomly Generate”  
ff=rand(tt)  
if ff.to\_i==0  
ff=1  
else  
ff=ff  
end  
puts ff.to\_i  
worksheet=workbook.worksheets(ff)  
puts “Worksheet Name”  
puts worksheet.Name  
workbook.Close  
excel.Quit

---

<div class="post-metadata">

**Author:** ![deeparaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85f322/32.png) [@deeparaj](https://www.ruby-forum.com/u/deeparaj)\
**Post date:** [February 25, 2009, 9:01am UTC](https://www.ruby-forum.com/t/fetch-an-excel-sheet-name-in-ruby/161221/4 "2009-02-25T09:01:40Z")

</div>

Hi,  
Thanks those who help me

```
        Here is the coding.which i got the excel sheet name.but i 

```

have a doubt how to use minimum and maximum value to generate random  
number in ruby.

require ‘win32ole’  
require ‘rubygems’  
excel = WIN32OLE.new(“excel.application”)  
excel.visible =false  
workbook = excel.workbooks.open(“E:\Book1.xls”)  
tt=workbook.Worksheets.count  
puts “Number of Worksheets”  
puts tt.to\_i  
puts “Randomly Generate”  
ff=rand(tt)  
if ff.to\_i==0  
ff=1  
else  
ff=ff  
end  
puts ff.to\_i  
worksheet=workbook.worksheets(ff)  
puts “Worksheet Name”  
puts worksheet.Name  
workbook.Close  
excel.Quit
