From: Jan Svitok Date: 2006-11-20T22:33:20+09:00 Subject: Re: How to translate a VBA code into Ruby script On 11/20/06, Li Chen wrote: > Hi all, > > I need to use WIN32OLE to do some Excel automation. I read some > documents and search google.The examples of how to use WIN32OLE are > almost the same. But none of them show how to translate a VBA code into > Ruby. Here are the VBA codes: > > Sub AddNew() > Set NewBook = Workbooks.Add > With NewBook > .Title = "All Sales" > .Subject = "Sales" > .SaveAs Filename:="Allsales.xls" > End With > End Sub > > > And here are some Ruby codes: require 'win32ole' excel=WIN32OLE.new('Excel.Application') #Set NewBook = Workbooks.Add newbook=excel.Workbooks.Add #With NewBook # .Title = "All Sales" newbook.Title = "All Sales" # .Subject = "Sales" newbook.Subject = "Sales" # .SaveAs Filename:="Allsales.xls" newbook.SaveAs Filename => "Allsales.xls" or newbook['Title'] = "All Sales" newbook['Subject'] = "Sales" newbook.SaveAs Filename => "Allsales.xls" please read http://ruby-doc.org/docs/ProgrammingRuby/html/win32.html and http://ruby-doc.org/stdlib/libdoc/win32ole/rdoc/index.html