Win32OLE. Opening an existing file.

P

Peter Bailey

Hi,
Can someone tell me how I can use Win32OLE to open an existing file? All
the doc I've seen just shows you how to start a new file, like this:

require 'Win32ole'
excel = WIN32OLE.new("excel.application")

Thanks,
Peter
 
V

Victor 'Zverok' Shepelev

Peter Bailey (pbailey@bna=2Ecom)
26/10/2006 15:44:12
Hi,
Can someone tell me how I can use Win32OLE to open an existing file? All=
the doc I've seen just shows you how to start a new file, like this:

require 'Win32ole'
excel =3D WIN32OLE=2Enew("excel=2Eapplication")

excel =3D WIN32OLE=2Enew('excel=2Eapplication')
book =3D excel=2EWorkbooks=2EOpen(path)

Typical answer for all similar questions: open Excel, start macro recordin=
g, do what you want, stop macro recording=2E Open recorded macro - it woul=
d be in VBA, but can be ported into Ruby w=2E WIN32OLE pretty straightforw=
ard=2E

V=2E
 
P

Peter Bailey

Victor said:
Peter Bailey ([email protected])
26/10/2006 15:44:12


excel = WIN32OLE.new('excel.application')
book = excel.Workbooks.Open(path)

Typical answer for all similar questions: open Excel, start macro
recording, do what you want, stop macro recording. Open recorded macro -
it would be in VBA, but can be ported into Ruby w. WIN32OLE pretty
straightforward.

V.

Thanks, Victor. I tried it with an existing file, and, it worked! It's
pretty slow, but, the books warned me about that. So, are you saying
that all of the WIN32OLE instructions are simply VBA instructions? So,
technically, I could derive my answers by just looking at the VBA help
in Word or Excel??
 
P

Peter Bailey

Ken said:
Precisely. VBA is just another language for controllng OLE objects, so
the
same API's are available for VBA and Ruby (and any other language you
might choose that talks OLE).

--Ken

Interesting. I noticed that, in the Win part of these instructions, the
path was only respected when done with "\" instead of the Rubyish "/."
So, it really is one world within another. Thanks!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top