# Unable to open Excel file

**URL:** <https://www.ruby-forum.com/t/unable-to-open-excel-file/156508>\
**Category:** Ruby\
**Created:** [December 29, 2008, 9:47am UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508 "2008-12-29T09:47:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![riya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@riya](https://www.ruby-forum.com/u/riya)\
**Post date:** [December 29, 2008, 9:47am UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508/1 "2008-12-29T09:47:57Z")

</div>

i am using below code for opening Excel application.  
But it not opening Excel file.

Code:-  
require ‘win32ole’

excel = WIN32OLE.new(“excel.application”)  
excel.visible = true  
workbook = excel.workbooks.open(“c:\temp.xls”)  
worksheet=workbook.worksheets(1)

i just want to open a excel file and write text in it.kindly help me.

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![riya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@riya](https://www.ruby-forum.com/u/riya)\
**Post date:** [December 30, 2008, 7:32am UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508/2 "2008-12-30T07:32:33Z")

</div>

Hi David,

What happens when you run this code?

> > only Console opens(command prompt)

Does the Excel window appear?

> > No

Do you receive an error?

> > No message appears

Do you have Excel installed on that PC?

> > Ms Excel is installed

Does the workbook already exist? Or are you looking to create a new  
workbook?

> > already exists

Problem - unable to open Excel with this code.  
Want to open (visible) and want to write text and then save.

Thanks  
Riya

David M. wrote:

> Riya Rai wrote:
> 
> > i am using below code for opening Excel application.  
> > But it not opening Excel file.
> > 
> > Code:-  
> > require ‘win32ole’
> > 
> > excel = WIN32OLE.new(“excel.application”)  
> > excel.visible = true  
> > workbook = excel.workbooks.open(“c:\temp.xls”)  
> > worksheet=workbook.worksheets(1)
> > 
> > i just want to open a excel file and write text in it.kindly help me.
> > 
> > Thanks in Advance
> 
> You’ll need to provide more details.
> 
> What happens when you run this code?  
> Does the Excel window appear?  
> Do you receive an error?
> 
> Do you have Excel installed on that PC?  
> Does the workbook already exist? Or are you looking to create a new  
> workbook?
> 
> These links may help:
> 
> [Ruby on Windows: Automating Excel with Ruby: The Workbook Object](http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-workbook.html)
> 
> [Ruby on Windows: excel](http://rubyonwindows.blogspot.com/search/label/excel)
> 
> David

---

<div class="post-metadata">

**Author:** ![riya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@riya](https://www.ruby-forum.com/u/riya)\
**Post date:** [December 30, 2008, 8:30am UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508/3 "2008-12-30T08:30:11Z")

</div>

Riya,

Not sure if this is the problem but your code is:

excel = WIN32OLE.new(“excel.application”)

On David’s site, the line is:

excel = WIN32OLE::new(‘excel.Application’)

Notice the capital A in Application; however, in irb on my PC, it works  
irrespective of the case. So, that’s probably not the problem. What  
version of Excel is installed on the PC on which you are running the  
code? Do you get any other errors at all?

Could you try going line by line in irb to see if it dies anywhere?

Cheers,  
Mohit.  
12/30/2008 | 3:24 PM.

---

<div class="post-metadata">

**Author:** ![riya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@riya](https://www.ruby-forum.com/u/riya)\
**Post date:** [December 29, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508/4 "2008-12-29T14:33:07Z")

</div>

Riya Rai wrote:

> i am using below code for opening Excel application.  
> But it not opening Excel file.
> 
> Code:-  
> require ‘win32ole’
> 
> excel = WIN32OLE.new(“excel.application”)  
> excel.visible = true  
> workbook = excel.workbooks.open(“c:\temp.xls”)  
> worksheet=workbook.worksheets(1)
> 
> i just want to open a excel file and write text in it.kindly help me.
> 
> Thanks in Advance

You’ll need to provide more details.

What happens when you run this code?  
Does the Excel window appear?  
Do you receive an error?

Do you have Excel installed on that PC?  
Does the workbook already exist? Or are you looking to create a new  
workbook?

These links may help:

> **[Automating Excel with Ruby: The Workbook Object](http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby-workbook.html)**
>
> Previously, we looked at the Excel Application object. Today, we'll take it down a level and investigate the Workbooks collection and Workbo...

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

David

---

<div class="post-metadata">

**Author:** ![riya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@riya](https://www.ruby-forum.com/u/riya)\
**Post date:** [December 30, 2008, 11:02am UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508/5 "2008-12-30T11:02:20Z")

</div>

Thanks every one

Now the below code is working

'To open Excel file  
require ‘win32ole’

xl = WIN32OLE.new(‘Excel.Application’)

xl.Visible = 1

wb = xl.Workbooks.Open(‘c:\file.xls’)

Thanks again to all

Riya

Mohit S. wrote:

> Riya,
> 
> Not sure if this is the problem but your code is:
> 
> excel = WIN32OLE.new(“excel.application”)
> 
> On David’s site, the line is:
> 
> excel = WIN32OLE::new(‘excel.Application’)
> 
> Notice the capital A in Application; however, in irb on my PC, it works  
> irrespective of the case. So, that’s probably not the problem. What  
> version of Excel is installed on the PC on which you are running the  
> code? Do you get any other errors at all?
> 
> Could you try going line by line in irb to see if it dies anywhere?
> 
> Cheers,  
> Mohit.  
> 12/30/2008 | 3:24 PM.

---

<div class="post-metadata">

**Author:** ![riya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a183cd/32.png) [@riya](https://www.ruby-forum.com/u/riya)\
**Post date:** [December 30, 2008, 4:11pm UTC](https://www.ruby-forum.com/t/unable-to-open-excel-file/156508/6 "2008-12-30T16:11:33Z")

</div>

Riya Rai wrote:

> wb = xl.Workbooks.Open(‘c:\file.xls’)

What was the problem though?

Cheers,  
Mohit.  
12/30/2008 | 11:10 PM.
