Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MS Windows automation - howto use it?

0 views
Skip to first unread message

Nura...@aol.com

unread,
Mar 16, 2005, 7:31:59 AM3/16/05
to
Dear Ruby experts,

I would like to use Ruby's WIN32OLE and/or WIN32API capability to
automate a translation application.
In the documentation on the web, there are examples on how to
use Ruby to create Excel and Word documents and to write to them.

My problem is now that I do not know how to tell Ruby what to substitute in
the book example's lines

ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ie.gohome

so that my application is loaded ( is it always NameoftheProgram.Application
?)
and what methods are then available to that object. I need to pass text into
a field, for instance ....

Thank you for your help!

Best regards,

Axel


Dave Burt

unread,
Mar 16, 2005, 8:10:24 AM3/16/05
to
----- Original Message -----
<Nura...@aol.com> asked:

Martin Kahlert asked a similar question a few weeks ago, in the thread "Windows
automation":
http://rubyurl.com/pklBm [1]

Depending on what you want to do, you may find an answer there (there are about
3 suggestions in that thread, the worst of which is mine, I believe :).
Otherwise, check out Watir [2] and I'm sure there's at least one more project in
the RAA [1] that can help you with what you're trying to do.

Now, I'll try and answer your direct questions with some explanation of stuff
you don't seem to understand.
"InternetExplorer.Application" is known in Windows as a "program id". Others
might include "Excel.Application", "Word.Application", "Scripting.Regexp",
"Scripting.FileSystemObject" (but why would you use either of these latter from
Ruby?)
I am pretty sure you can substitute a program id in the WIN32OLE constructor
with a class id, which looks more like "{6BF52A52-394A-11D3-B153-00C04F79FAA6}"
(Flash object). It's just a different way to specify what OLE object to create.

How do you know what methods your new Flash object has? That's tricky - you
can't just use my_ole_object.methods, because it doesn't actually have any
special ones - it uses method_missing. You need to check the documentation for
the OLE object itself. When I'm developing using Word and Excel automation, I
usually develop that code in Word and Excel (record macros, use the help and the
object browser to help figure out how to do whatever I need to do) and then just
translate that to Ruby (it's pretty straightforward).

Cheers,
Dave

[1]
http://groups.google.com.au/groups?hl=en&lr=&safe=off&threadm=YBFVd.182663%24K7.21911%40news-server.bigpond.net.au&rnum=1&prev=/groups%3Fq%3Dmartin%2Bkahlert%2Bwindows%2Bautomation%26hl%3Den%26btnG%3DGoogle%2BSearch

[2] http://wtr.rubyforge.org/

Thomas

unread,
Mar 16, 2005, 10:42:36 AM3/16/05
to
> How do you know what methods your new Flash object has? That's tricky -
> you can't just use my_ole_object.methods, because it doesn't actually
> have any special ones - it uses method_missing.

Minor note: You could probably use the #ole_methods method to get a
(partial) list of known methods. Doesn't give you any information on
method arguments though which is why you would probably need the
documentation anyway.

Cheers,
Thomas.

Roshan James

unread,
Mar 17, 2005, 1:16:24 AM3/17/05
to
Ruby simply talk to the COM automation server that the office
applicatiosn expose. What that means is that it simply talks to the same
object model that macros in Vbscript talk to.

So whats the simply way of figuring out whats avilable? Simply just look
at the Object Browser that comes with office application. You can launch
the Vbscript editor that comes in Word or any of the other office apps
and then take a look at the Object Browser. This basically uses a COM
based reflection API to show you everything that office can do.

Further, if you pick up a book about VBA (Visual Basic for Applications)
programming, it will show a large part of the commonly used objects and
API.

Roshan

Martin DeMello

unread,
Mar 17, 2005, 1:32:29 AM3/17/05
to
Roshan James <ros...@microsoft.com> wrote:
>
> So whats the simply way of figuring out whats avilable? Simply just look
> at the Object Browser that comes with office application. You can launch
> the Vbscript editor that comes in Word or any of the other office apps
> and then take a look at the Object Browser. This basically uses a COM
> based reflection API to show you everything that office can do.

Hm - how hard would it be to get at this reflection API from ruby?

martin

Adelle Hartley

unread,
Mar 17, 2005, 2:06:55 AM3/17/05
to
> Hm - how hard would it be to get at this reflection API from ruby?
>
> martin
>

OLE object browser, in Ruby.

http://homepage1.nifty.com/markey/ruby/win32ole/index_e.html

Adelle.

Martin DeMello

unread,
Mar 17, 2005, 3:03:53 AM3/17/05
to
Adelle Hartley <ade...@bullet.net.au> wrote:
> > Hm - how hard would it be to get at this reflection API from ruby?
>

Thanks! That's pretty nifty.

martin

Roshan James

unread,
Mar 17, 2005, 5:57:52 AM3/17/05
to
Yeah essentiually this is how the Object browser that comes with the
Vbscript editor also works.
Roshan

// -----Original Message-----
// From: Martin DeMello [mailto:martin...@yahoo.com]
// Sent: Thursday, March 17, 2005 1:35 PM
// To: ruby-talk ML
// Subject: Re: MS Windows automation - howto use it?
//
// Adelle Hartley <ade...@bullet.net.au> wrote:
// > > Hm - how hard would it be to get at this reflection API
// from ruby?
// >
// > OLE object browser, in Ruby.
// >
// > http://homepage1.nifty.com/markey/ruby/win32ole/index_e.html
//
// Thanks! That's pretty nifty.
//
// martin
//
//

0 new messages