Win32OLE.const_load -- where to find missing constants

Discussion in 'Ruby' started by David Lewis, May 1, 2011.

  1. David Lewis

    David Lewis Guest

    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/.
     
    David Lewis, May 1, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Masaki Suketa
    Replies:
    4
    Views:
    419
    Dave Burt
    Mar 27, 2006
  2. Li Chen
    Replies:
    2
    Views:
    179
    Li Chen
    Dec 1, 2006
  3. djlewis
    Replies:
    0
    Views:
    121
    djlewis
    Dec 19, 2006
  4. zxem
    Replies:
    1
    Views:
    268
  5. Jamie Forrest

    win32ole method missing

    Jamie Forrest, Jan 30, 2009, in forum: Ruby
    Replies:
    1
    Views:
    135
    Jamie Forrest
    Jan 30, 2009
Loading...

Share This Page