Using OLE with Perl


ActivePerl-faq12 - Using OLE with Perl


How to use OLE automation with Perl - through the Win32::OLE module

Can I use OLE with Perl?

Yes - otherwise this FAQ wouldn't have been a separate FAQ. ;-)

If you want to use OLE with Perl you need the Win32::OLE module. And you need to read the documentation that comes with it.

use Win32::OLE doesn't export any variables and functions to the main namespace, so if you want easy access to the in and with functions you should load the module with

use Win32::OLE qw(in with);

What has changed with OLE since build 3xx

A lot - Gurusamy Sarathy and then Jan Dubois redesigned the code and added a bundle of enhancements. Old scripts should run with little or no modifications. When writing new scripts there is no excuse for not using the new Win32::OLE module options.

Look at the Win::OLE module documentation (under Incompatibilities).

How do I print a Microsoft Word document?

Use the method PrintOut on a document object, for example:

use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

my $Word = Win32::OLE->new('Word.Application', 'Quit');
# $Word->{'Visible'} = 1;