You can either import the constants directly into your namespace as
subs that return the constant value, or you can have them returned as
a hash reference with the constant name as the key and its value as
the value. Here's an example of the former:
use Win32::OLE::Const ("Microsoft Excel");
print "xlExcel5 = ", xlExcel5, "\n";
This produces something like:
xlExcel5 = 39
use Win32::OLE::Const;
my $constants = Win32::OLE::Const->Load("Microsoft Excel");
print "xlExcel5 = $constants->{xlExcel5}\n";
Notice that, in both cases, we're supplying a
regular expression for the name of the type library from which we
want to import. Win32::OLE::Const searches the
registry for matching type libraries and loads the one with the
highest version number (you can override this by supplying the
version you want). You can also specify the language
you'd like. The parameters (for either
Load or Win32::OLE::Const) are
the typelib regular expression, the major version number, the minor
version number, and the locale (LCID).
You can also provide the Load method with an
automation object, which is then queried for its type library.
Interestingly, the documentation notes that this seems to be slower
than searching the Registry (though neither is really speedy with a
large automation server like Excel). Here's an
example of that:
use Win32::OLE;
use Win32::OLE::Const;
# Create an Excel application object
my $xl = Win32::OLE->new('Excel.Application', 'Quit') ||
die "Can't create Excel: ", Win32::OLE->LastError;
# Import the constants from it
my $constants = Win32::OLE::Const->Load($xl);