Hang on a sec.  By assigning sheet = application, you're setting the sheet
objection to the application object--which means you've lost access to the
sheet object by reassigning it.  If you simply said

application.activecell.offset(1,0).activate

you'd get the same effect, and you'd still have a sheet object.  

This is because ActiveCell is a property of the application, not of the
workbook nor of the worksheet.  You can confirm this by opening up an Excel
sheet, choosing the menu bar's Tools / Macro / Visual Basic Editor, and then
pressing F2 for the Object Browser.  Double-click on ActiveCell and you'll
see (about a third of the way up from the bottom of the screen) that it's a
global property of Excel.Application.  I presume this is because the authors
of Excel's OLE Automation only wanted one active cell in the entire
application, not one active cell per worksheet or workbook, but reading the
minds of those folks is difficult.

Note that none of this has anything to do with Ruby per se.  They're not
"the Ruby objects" here; they're OLE/COM objects.  You would have
encountered the same kinds of confusion were you using Visual Basic.  (Lord
knows I did.)

One fine day, I'll write a really good Ruby-Excel interface.  Don't hold
your breath, though. :)

---Michael B.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Beaton, Malcolm
Sent: January 4, 2006 4:27 PM
To: wtr-general@rubyforge.org
Subject: Re: [Wtr-general] selecting cells in Excell using activecell

THANK YOU MARK

Works a treat

Now excuse my ignorance but why does <<sheet = application>> work but
<<sheet = application.activesheet>> not work? My experience with
Applescript suggests I was in the wrong object but the ruby objects
still confuse me a little 

Malcolm Beaton


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Cain, Mark
Sent: 04 January 2006 18:05
To: wtr-general@rubyforge.org
Subject: Re: [Wtr-general] selecting cells in Excell using activecell

This you might find helpful http://rubygarden.org/ruby?ScriptingExcel 

Also, I was playing around with your script and this worked for me:

sheet = application
sheet.activecell.offset(1,0).activate

--Mark

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Beaton, Malcolm
Sent: Wednesday, January 04, 2006 9:15 AM
To: wtr-general@rubyforge.org
Subject: [Wtr-general] selecting cells in Excell using activecell


Maybe a little out of scope for this group but I am trying to write and
retrieve cell data from Excel iteratively with ruby using the activecell
property. Only problem is it does not seem to work.

My script is basically

require 'win32ole'
application = WIN32OLE.new('Excel.Application')

application.visible = TRUE
workbook = application.Workbooks.Add();
worksheet = workbook.Worksheets(1);
(1..4).each do |x|
dirArray = ['North','South','East','West']
worksheet.Range('A' + (x.to_s)).value = dirArray[(x-1)]
end

sheet = application.activesheet
sheet.activecell.offset(1,0).activate

and I always get the error 
excell.rb:47:in `method_missing': Unknown property or method
`activecell' (WIN32OLERuntimeError)

Am I missing a lib or something? I can find no reference to other people
having this issue

Any help would be appreciated

Malcolm Beaton

_____________________________________________________________________
This e-mail has been scanned for viruses by MessageLabs. The information
contained in this message is confidential and is intended for the
addressee only. If you have received this message in error, please
notify Conchango plc as soon as possible. The unauthorised use,
disclosure, copying or alteration of this message is prohibited and may
be unlawful. The internet cannot guarantee the integrity of this message
and therefore Conchango plc will not be liable for the message if
modified.  

Reg. Heritage House, Church Road, Egham, Surrey, TW20 9QD T 44 (0) 1784
222 222 F 44 (0) 1784 222 200 E [EMAIL PROTECTED]  No. 2598884

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

_____________________________________________________________________
This e-mail has been scanned for viruses by MessageLabs. The information
contained in this message is confidential and is intended for the addressee
only. If you have received this message in error, please notify Conchango
plc as soon as possible. The unauthorised use, disclosure, copying or
alteration of this message is prohibited and may be unlawful. The internet
cannot guarantee the integrity of this message and therefore Conchango plc
will not be liable for the message if modified.  

Reg. Heritage House, Church Road, Egham, Surrey, TW20 9QD T 44 (0) 1784 222
222 F 44 (0) 1784 222 200 E [EMAIL PROTECTED]  No. 2598884

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to