From: Paul Lutus Date: 2006-09-24T01:00:17+09:00 Subject: Re: ruby/win32ole Excel Move problem Craig Moran wrote: > Sorting the sheets in Ruby works great. Thought I'd share the code for > any other folks who wish to perform their Excel macros in Ruby. > > require 'win32ole' > > xl = WIN32OLE.new("excel.application") > xl['Visible'] = true > xl.workbooks.open("filename.xls") > > sheet_array = [] > 1.upto(xl.sheets.count) { |x| sheet_array< sheet_array.sort!.reverse! Slightly faster: sheet_array.sort.reverse! Only the result needs to be applied to the calling object. > sheet_array.each { |x| xl.sheets(x).move xl.sheets(1) } Just a quibble: sheet_array.each { |name| spreadsheet.sheets(name).move spreadsheet.sheets(1) } More self-documenting. > Thanks again for the help, Paul! You are very welcome. It's not every day that I get to walk the untested, hand-waving, theoretical high-wire. I much prefer to test before posting, but this time I couldn't. :) -- Paul Lutus http://www.arachnoid.com