# Win32ole question

**URL:** <https://www.ruby-forum.com/t/win32ole-question/84151>\
**Category:** Ruby\
**Created:** [February 1, 2007, 10:08pm UTC](https://www.ruby-forum.com/t/win32ole-question/84151 "2007-02-01T22:08:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bitsmith](https://www.ruby-forum.com/u/bitsmith)\
**Post date:** [February 1, 2007, 10:08pm UTC](https://www.ruby-forum.com/t/win32ole-question/84151/1 "2007-02-01T22:08:30Z")

</div>

can anybody point me to a good web page or know how to:  
using ruby’s WIN32OLE ‘save as’ a current  
Worksheet into a csv format by only using  
ruby’s WIN32OLE access?

---

<div class="post-metadata">

**Author:** ![bitsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bitsmith](https://www.ruby-forum.com/u/bitsmith)\
**Post date:** [February 2, 2007, 12:24am UTC](https://www.ruby-forum.com/t/win32ole-question/84151/2 "2007-02-02T00:24:34Z")

</div>

On 2/1/07, Dave R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> can anybody point me to a good web page or know how to:  
> using ruby’s WIN32OLE ‘save as’ a current  
> Worksheet into a csv format by only using  
> ruby’s WIN32OLE access?

I’d try this: (I’m assuming that you want to work with excel)

1. record a macro doing the desired action (i.e. start recording  
macro, save the worksheet as csv file and stop recording).

2. open VBA editor to see the source code of the macro

3. translate it into ruby/WIN32OLE

For the last step, you’ll need to pick up only part of the macro -  
there’ll be probably other commands that you don’t need. Look the  
commands in the help or on MSDN to see what they do. For the Ruby  
part, there’s a chapter on this in Programming Ruby  
([Programming Ruby: The Pragmatic Programmer's Guide](http://ruby-doc.org/docs/ProgrammingRuby/html/win32.html)). You can  
search the archive of the list for more info (Li Chen was a guy that  
worked a lot with Excel, so look up his threads)

---

<div class="post-metadata">

**Author:** ![bitsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bitsmith](https://www.ruby-forum.com/u/bitsmith)\
**Post date:** [February 2, 2007, 3:45am UTC](https://www.ruby-forum.com/t/win32ole-question/84151/3 "2007-02-02T03:45:44Z")

</div>

On Feb 1, 4:08 pm, Dave R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> can anybody point me to a good web page or know how to:  
> using ruby’s WIN32OLE ‘save as’ a current  
> Worksheet into a csv format by only using  
> ruby’s WIN32OLE access?
> 
> –  
> Posted viahttp://www.ruby-forum.com/.

workbook.SaveAs ‘myfile.csv’, xlCSV

…where xlCSV = 6.

[http://www.rubygarden.org:3000/Ruby/page/show/ScriptingExcel](http://www.rubygarden.org:3000/Ruby/page/show/ScriptingExcel)

Mully

---

<div class="post-metadata">

**Author:** ![bitsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bitsmith](https://www.ruby-forum.com/u/bitsmith)\
**Post date:** [February 3, 2007, 1:30am UTC](https://www.ruby-forum.com/t/win32ole-question/84151/4 "2007-02-03T01:30:44Z")

</div>

On Feb 2, 11:20 am, Dave R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > workbook.SaveAs ‘myfile.csv’, xlCSV  
> > …where xlCSV = 6.  
> > …dave
> 
> –  
> Posted viahttp://www.ruby-forum.com/.- Hide quoted text -
> 
> - Show quoted text -

note: if the workbook already defined then workbook.SavesAs(“c:/augcsv/  
myfile1.csv”, xlCSV) works

---

<div class="post-metadata">

**Author:** ![bitsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/9de053/32.png) [@bitsmith](https://www.ruby-forum.com/u/bitsmith)\
**Post date:** [February 2, 2007, 5:20pm UTC](https://www.ruby-forum.com/t/win32ole-question/84151/5 "2007-02-02T17:20:05Z")

</div>

David M. wrote:

> On Feb 1, 4:08 pm, Dave R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > can anybody point me to a good web page or know how to:  
> > using ruby’s WIN32OLE ‘save as’ a current  
> > Worksheet into a csv format by only using  
> > ruby’s WIN32OLE access?
> > 
> > –  
> > Posted viahttp://www.ruby-forum.com/.
> 
> workbook.SaveAs ‘myfile.csv’, xlCSV
> 
> …where xlCSV = 6.
> 
> [http://www.rubygarden.org:3000/Ruby/page/show/ScriptingExcel](http://www.rubygarden.org:3000/Ruby/page/show/ScriptingExcel)
> 
> Mully

thanx…fyi…it’s a combo of both of your response…i did a macro and  
used your’s above to get…  
excel.ActiveWorkbook.SaveAs(“c:\augcsv\myfile1.csv”, xlCSV)  
…where xlCSV = 6.  
…dave
