Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Win32OLE.const_load -- where to find missing constants

Reply
Thread Tools

Win32OLE.const_load -- where to find missing constants

 
 
David Lewis
Guest
Posts: n/a
 
      05-01-2011
I just spent a couple of hours tracking this down, so I'm posting it for
anyone else who might have trouble finding various Win32OLE constants.

I needed constants msoGroup and msoAutoShape in PowerPoint (determined
by running VBA code in PPT and inspecting the variables in the locals
window). According to standard practice explained in many places on the
web, this code should have done it...

module MSO
end

$ppt = WIN32OLE.new('PowerPoint.Application')
WIN32OLE.const_load($ppt, MSO)

But it didn't -- those constant did not get loaded. I got a total of
1399 constants loaded, but many that I needed were missing. After
rummaging around a bit, I found that there are a lot of symbols in the
MS Object library, and further experimentation indicated that version
11.0 worked for my installation -- Office 2010.

So, I added this line to the above...

WIN32OLE.const_load('Microsoft Office 11.0 Object Library', MSO)

And now MSO has all the constants from both sources, including the two I
need, though at the price of "warning: already initialized constant
CONSTANTS".

For your added pleasure, here is the complete code, including what I
used to rummage around in the debugger (RubyMine -- recently adopted and
working nicely after Oracle decommitted Ruby from the formerly lovely
NetBeans). kill_CONSTANTS is to eliminate the warning. I'm sure
there are slicker ways to code all this, but it worked.

$ppt = WIN32OLE.new('PowerPoint.Application')
$ppt.Visible = true
WIN32OLE.const_load($ppt, MSO)
MSO::kill_CONSTANTS
WIN32OLE.const_load('Microsoft Office 11.0 Object Library', MSO)
y = MSO::MsoAutoShape
x = MSO::MsoGroup

def class_constants(cls)
cls.constants.collect do |sym|
sym.to_s + "=" + eval(cls.to_s + "::" + sym.to_s).to_s
end.sort!
end

cc = class_constants(MSO)

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 3 02-14-2011 05:28 AM
How to exclude action of Find::Find::find in subdirectories withknown names? vdvorkin Perl Misc 0 02-10-2011 05:18 PM
Re: missing feature classes and missing fields Gary Herron Python 2 07-04-2006 10:29 PM
Dynamic finding of missing constants. Ola Bini Ruby 3 11-25-2005 04:31 PM
Find.find does not find orphaned links? Wybo Dekker Ruby 1 11-15-2005 02:50 PM



Advertisments