Why this script doesn't work?

Discussion in 'Ruby' started by Li Chen, Dec 4, 2006.

  1. Li Chen

    Li Chen Guest

    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 <Unknown>
    <No Description>
    HRESULT error code:0x80020009
    Exception occurred. from test3.rb:13
    >Exit code: 1


    --
    Posted via http://www.ruby-forum.com/.
     
    Li Chen, Dec 4, 2006
    #1
    1. Advertising

  2. Li Chen

    Li Chen Guest

    Paul Lutus 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/

    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

    --
    Posted via http://www.ruby-forum.com/.
     
    Li Chen, Dec 4, 2006
    #2
    1. Advertising

  3. Li Chen

    ChrisH Guest

    Li Chen wrote:
    ....
    > cells = sheets.cells("A1:A5")


    Try:
    cells = sheets.Range("A1:A5")


    Cheers
    Chris
     
    ChrisH, Dec 4, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Bass
    Replies:
    3
    Views:
    369
    Marina
    Jul 3, 2003
  2. Replies:
    6
    Views:
    300
    Fredrik Lundh
    Apr 2, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    977
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,216
    Smokey Grindel
    Dec 2, 2006
  5. rigo
    Replies:
    0
    Views:
    188
Loading...

Share This Page