Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Extract Outlook Telephone Numbers

by Corion (Patriarch)
on Mar 02, 2001 at 19:10 UTC ( [id://61803]=sourcecode: print w/replies, xml ) Need Help??
Category: Win32 Stuff; OLE Automation
Author/Contact Info Max Maischein (Corion) corion@informatik.uni-frankfurt.de
Description: This is a small example on how to use the MS Outlook object model from within Perl (under Win32 of course) to extract contacts data. If you have the Outlook object model chart at hand, it's easy to automate other tasks such as sending mail or creating contacs as well. This snippet needs Outlook to be open and the Contacts view must be active, because I was too lazy to drill my way down from Outlook->Application to the Contacts view.

Update:I added the missing <code> tags myself. Even more stupid I am ...

Update 2:Some documentation - the 069 is my local area code.

#!/usr/bin/perl -w

use strict;
use Win32::OLE;

my @PhoneProperties = (
  "Business2TelephoneNumber",
  "BusinessFaxNumber",
  "BusinessTelephoneNumber",
  "CarTelephoneNumber",
  "Home2TelephoneNumber",
  "HomeTelephoneNumber",
  "ISDNNumber",
  "MobileTelephoneNumber",
  "OtherFaxNumber",
  "OtherTelephoneNumber",
  "PrimaryTelephoneNumber",
);

my $outlook;
$outlook = Win32::OLE->new('Outlook.Application');

my $activeexplorer;
$activeexplorer = $outlook->ActiveExplorer;

print $activeexplorer->Caption,"\n";

my $items = $activeexplorer->CurrentFolder->Items;
print $items->Count,"\n";

my $linenumber = 1;
print "NR;NAME;TELNUM\n";

my $Kontakt;
my $PhoneProp;
my $ItemIndex = 1;

while ($ItemIndex <= $items->Count) {
  $Kontakt = $items->item($ItemIndex);

  foreach $PhoneProp (@PhoneProperties) {
    my $number = $Kontakt->{"$PhoneProp"};
    if ($number) {
      # Prefix local area code unless an area code
      # is already given
      if ($number !~ /^0/) { $number = "069$number" };
      $number =~ s/ +//g;
      $number =~ s/-+//g;
      print $linenumber++, ";", $Kontakt->FullName,";'$number\n";
      #print "$number=", substr( $Kontakt->FullName, 1, 15 ),"\n";
    };
  };

  $ItemIndex++;
};
Replies are listed 'Best First'.
Re: Extract Outlook Telephone Numbers
by dze27 (Pilgrim) on Mar 03, 2001 at 01:49 UTC

    neat! This worked for me except it did not print the Caption on line 26. I'm using Outlook 97 (poor me) so maybe that's the problem. $activeexplorer->CurrentFolder->Name seems to work though.

    What is the meaning of 069 (line 46)?

    I added some code after line 24 to automatically change to the Contacts folder:

    use Win32::OLE::Const 'Microsoft Outlook';
    and
    my $outlook; $outlook = Win32::OLE->new('Outlook.Application'); my $namespace = $outlook->GetNamespace("MAPI"); my $Folder = $namespace->GetDefaultFolder(olFolderContacts); print $Folder->Name,"\n"; my $items = $Folder->Items; print $items->Count,"\n";
    does it. (Between "my $outlook;" and "print $items->Count,"\n";)

    This doesn't change folders on the running copy of Outlook. The extra "use" line is required for using olFolderContacts.

Re: Extract Outlook Telephone Numbers
by jlf (Scribe) on Mar 08, 2002 at 22:29 UTC
    Corion,

    In the spirit of TMTOWTDI, check this node for a way to look up phone numbers without having an Outlook session open.

    Josh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://61803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-03-29 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found