Give this a try -- it works for me.
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
#what properties do we want to get from Outlook?
my @properties = (
"Fullname",
"PrimaryTelephoneNumber",
"BusinessTelephoneNumber",
"Business2TelephoneNumber",
"BusinessFaxNumber",
"HomeTelephoneNumber",
"Home2TelephoneNumber",
"MobileTelephoneNumber",
"OtherFaxNumber",
"OtherTelephoneNumber",
"Email1Address",
"Email1AddressType",
"Email2Address",
"Email2AddressType"
);
#get an Outlook object
my $outlook = Win32::OLE->new('Outlook.Application');
unless ($outlook)
{
my $error = Win32::OLE->LastError();
die "Couldn't start Outlook: $error";
}
#get the Contacts folder
my $namespace = $outlook->GetNamespace("MAPI");
my $folder = $namespace->GetDefaultFolder(olFolderContacts);
my $items = $folder->Items;
print "Folder: ", $folder->Name,"\n";
print "Total entries: ",$items->Count,"\n";
#print out the header
print join(",",@properties),"\n";
#loop through the items, printing out each one
foreach my $index (1..$items->Count)
{
my $contact = $items->item($index);
my @entry;
push @entry, $contact->{$_} foreach (@properties);
print join(",",@entry),"\n";
};
Note that the VB documentation is the best you'll get in most cases. Once you learn how Win32::OLE works though, you can usually reference the VB docs to figure out the object model then guess at what is needed to make it work with perl and Win32::OLE.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.