WIN32OLE.Open - runtime error

1,006 views
Skip to first unread message

Shiv

unread,
Jul 8, 2010, 7:30:47 AM7/8/10
to watir-...@googlegroups.com
Hello,
 
I am trying to open a excel file and write data, but i m getting runtime error
I checked the path is correct
new method works fine but open method throws error...can u pls help me figure out this problem
 
Code:
require 'win32ole'
excel = WIN32OLE.new('excel.application')
excel.visible = true
excel.Workbooks.Open('D:\shiv.xls')
excel.range('A1').value = 'Hello, world.'
excel.Close
excel.Quit
 
 
Error:
C:\Ruby\bin>ruby C:\Ruby_Scripts\Ex_open.rb
C:/Ruby_Scripts/Ex_open.rb:6:in `method_missing': Open (WIN32OLERuntimeError)
    OLE error code:800A03EC in Microsoft Office Excel
      'D:\shiv.xls' could not be found. Check the spelling of the file name, and
 verify that the file location is correct.
If you are trying to open the file from your list of most recently used files, m
ake sure that the file has not been renamed, moved, or deleted.
    HRESULT error code:0x80020009
      Exception occurred.
        from C:/Ruby_Scripts/Ex_open.rb:6
 
Regards,
Shiv

SMF SMF

unread,
Jul 8, 2010, 7:39:07 AM7/8/10
to watir-...@googlegroups.com
Change 2nd line to as below-
 
excel = WIN32OLE::new('excel.application')

--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
You received this message because you are subscribed to http://groups.google.com/group/watir-general
To post: watir-...@googlegroups.com
To unsubscribe: watir-genera...@googlegroups.com

Shiv

unread,
Jul 8, 2010, 8:08:14 AM7/8/10
to watir-...@googlegroups.com
Thanks, BUT i get same error, I changed the 2nd line to
 
excel = WIN32OLE::new('excel.application')

Basim Baassiri

unread,
Jul 8, 2010, 9:25:28 AM7/8/10
to watir-...@googlegroups.com
is the d drive that you are specifying a network share? also, does the file exist with the correct spelling

Basim

SMF SMF

unread,
Jul 8, 2010, 9:41:18 AM7/8/10
to watir-...@googlegroups.com
excel.Workbooks.Open(''D:\shiv.xls'') - change this line also and make shiv.xls exist in D-drive

Shiv

unread,
Jul 8, 2010, 11:09:35 AM7/8/10
to watir-...@googlegroups.com
hi,

d drive is not in network share, it is local drive of my machine

shiv

On Thu, Jul 8, 2010 at 6:55 PM, Basim Baassiri <ba...@baassiri.ca> wrote:

Shiv

unread,
Jul 8, 2010, 11:12:03 AM7/8/10
to watir-...@googlegroups.com
sorry,I did not get you...because what you are suggesting already exists..I mean my excel file shiv.xls is already in D-drive, I have used single quotes..you want me to use double quotes ? I have already done that it doesnt help

Basim Baassiri

unread,
Jul 8, 2010, 11:50:47 AM7/8/10
to watir-...@googlegroups.com
My only conclusion is that the file located at D:\shiv.xls does not exist

I've tried the following with success (locally on my machine using C: drive)
-setting the file to readonly, readonly and hidden
-removed all file permissions (deny all)

sorry i couldn't help out 

Basim

Chuck van der Linden

unread,
Jul 8, 2010, 11:52:19 AM7/8/10
to Watir General
Backslash is the 'escaping' character in ruby, for example to insert
a single quote as part of a single quoted string you would do

s='that\'s the answer'

If you : puts s
you would get: that's the answer

Similarly it would be used to insert a double-quote inside a double
quoted string.

So the end result is that \ is always seen as an escaping charcter, no
matter what kind of quotes you are enclosing the string in.

To get a single \ inside a string you need to double it

try

excel.Workbooks.Open('D:\\shiv.xls')

reading this might help your understanding, http://www.ruby-forum.com/topic/130674


On Jul 8, 8:12 am, Shiv <tms...@gmail.com> wrote:
> sorry,I did not get you...because what you are suggesting already exists..I
> mean my excel file shiv.xls is already in D-drive, I have used single
> quotes..you want me to use double quotes ? I have already done that it
> doesnt help
>
>
>
> On Thu, Jul 8, 2010 at 7:11 PM, SMF SMF <shaikm.fi...@gmail.com> wrote:
> > excel.Workbooks.Open(''D:\shiv.xls'') - change this line also and make
> > shiv.xls exist in D-drive
>
> > On Thu, Jul 8, 2010 at 6:55 PM, Basim Baassiri <ba...@baassiri.ca> wrote:
>
> >> is the d drive that you are specifying a network share? also, does the
> >> file exist with the correct spelling
>
> >> Basim
>
> >> On Thu, Jul 8, 2010 at 8:08 AM, Shiv <tms...@gmail.com> wrote:
>
> >>> Thanks, BUT i get same error, I changed the 2nd line to
>
> >>> excel = WIN32OLE::new('excel.application')
> >>>   On Thu, Jul 8, 2010 at 5:09 PM, SMF SMF <shaikm.fi...@gmail.com>wrote:
>
> >>>> Change 2nd line to as below-
>
> >>>> excel = WIN32OLE::new('excel.application')
>
> >>>>   On Thu, Jul 8, 2010 at 5:00 PM, Shiv <tms...@gmail.com> wrote:
>
> >>>>>   Hello,
>
> >>>>> I am trying to open a excel file and write data, but i m getting
> >>>>> runtime error
> >>>>>  I checked the path is correct
> >>>>> new method works fine but open method throws error...can u pls help me
> >>>>> figure out this problem
>
> >>>>> *Code:*
> >>>>> require 'win32ole'
> >>>>> excel = WIN32OLE.new('excel.application')
> >>>>> excel.visible = true
> >>>>> excel.Workbooks.Open('D:\shiv.xls')
> >>>>> excel.range('A1').value = 'Hello, world.'
> >>>>> excel.Close
> >>>>> excel.Quit
>
> >>>>> *Error:*
> >>>>> C:\Ruby\bin>ruby C:\Ruby_Scripts\Ex_open.rb
> >>>>> C:/Ruby_Scripts/Ex_open.rb:6:in `method_missing': Open
> >>>>> (WIN32OLERuntimeError)
> >>>>>     OLE error code:800A03EC in Microsoft Office Excel
> >>>>>       'D:\shiv.xls' could not be found. Check the spelling of the file
> >>>>> name, and
> >>>>>  verify that the file location is correct.
> >>>>> If you are trying to open the file from your list of most recently used
> >>>>> files, m
> >>>>> ake sure that the file has not been renamed, moved, or deleted.
> >>>>>     HRESULT error code:0x80020009
> >>>>>       Exception occurred.
> >>>>>         from C:/Ruby_Scripts/Ex_open.rb:6
>
> >>>>> Regards,
> >>>>> Shiv
>
> >>>>> --
> >>>>> Before posting, please readhttp://watir.com/support. In short: search
> >>>>> before you ask, be nice.
>
> >>>>> You received this message because you are subscribed to
> >>>>>http://groups.google.com/group/watir-general
> >>>>> To post: watir-...@googlegroups.com
> >>>>> To unsubscribe: watir-genera...@googlegroups.com<watir-general%2Bunsubscribe@goog­legroups.com>
>
> >>>> --
> >>>> Before posting, please readhttp://watir.com/support. In short: search
> >>>> before you ask, be nice.
>
> >>>> You received this message because you are subscribed to
> >>>>http://groups.google.com/group/watir-general
> >>>> To post: watir-...@googlegroups.com
> >>>> To unsubscribe: watir-genera...@googlegroups.com<watir-general%2Bunsubscribe@goog­legroups.com>
>
> >>> --
> >>> Before posting, please readhttp://watir.com/support. In short: search
> >>> before you ask, be nice.
>
> >>> You received this message because you are subscribed to
> >>>http://groups.google.com/group/watir-general
> >>> To post: watir-...@googlegroups.com
> >>> To unsubscribe: watir-genera...@googlegroups.com<watir-general%2Bunsubscribe@goog­legroups.com>
>
> >>   --
> >> Before posting, please readhttp://watir.com/support. In short: search
> >> before you ask, be nice.
>
> >> You received this message because you are subscribed to
> >>http://groups.google.com/group/watir-general
> >> To post: watir-...@googlegroups.com
> >> To unsubscribe: watir-genera...@googlegroups.com<watir-general%2Bunsubscribe@goog­legroups.com>
>
> >  --
> > Before posting, please readhttp://watir.com/support. In short: search
> > before you ask, be nice.
>
> > You received this message because you are subscribed to
> >http://groups.google.com/group/watir-general
> > To post: watir-...@googlegroups.com
> > To unsubscribe: watir-genera...@googlegroups.com<watir-general%2Bunsubscribe@goog­legroups.com>- Hide quoted text -
>
> - Show quoted text -

Shiv

unread,
Jul 9, 2010, 1:52:14 AM7/9/10
to watir-...@googlegroups.com
Hi chuck,

Thx for the info

I have done what you have suggested but it doesn't help. I get same error

my script fails in the second line itself, I get a runtime error from WINN32OLE...is it something to do with watir version I am using?

my watir version is watir-1.6.5

require 'win32ole'
excel = WIN32OLE::new('excel.application')
excel.visible = true

wb = excel.Workbooks.Open('D:\\shiv.xls')

Shiv
 


--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.

windy

unread,
Jul 10, 2010, 11:26:25 AM7/10/10
to watir-...@googlegroups.com
try this, excel.Workbooks.Open('d:/shiv.xls')
it should be ok. hope it useful.

锟斤拷 Thu, 08 Jul 2010 19:30:47 +0800锟斤拷Shiv <tms...@gmail.com> 写锟斤拷:

> Hello,
>
> I am trying to open a excel file and write data, but i m getting runtime
> error
> I checked the path is correct
> new method works fine but open method throws error...can u pls help me
> figure out this problem
>

> *Code:*


> require 'win32ole'
> excel = WIN32OLE.new('excel.application')
> excel.visible = true
> excel.Workbooks.Open('D:\shiv.xls')
> excel.range('A1').value = 'Hello, world.'
> excel.Close
> excel.Quit
>
>

> *Error:*

Reply all
Reply to author
Forward
0 new messages