Win32OLE.const_load -- where to find missing constants

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

$ppt =‘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

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 =‘PowerPoint.Application’)
$ppt.Visible = true
WIN32OLE.const_load($ppt, MSO)
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

cc = class_constants(MSO)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs