Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re:(4)What do you want to delete?

by cacharbe (Curate)
on May 29, 2002 at 19:58 UTC ( [id://170205]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Check your property Names in the Outlook ContactItem Class
in thread Perl control of Outlook import to contacts with win32::OLE

I would look at the parameters on which you DO want to delete, and work it something like this. (Based on the following)
use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; $|++; $Win32::OLE::Warn = 3; # Throw Errors, I'll catch them my $OL = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application', 'Quit'); my $NameSpace = $OL->GetNameSpace("MAPI");

I used this to fill in some values:

my $Contacts = $NameSpace->Folders("Personal Folders")->Folders("Cont +acts"); my @names = qw(Chuck Charles Charlie Chuckles); foreach my $name (@names){ my $NewContact = $Contacts->Items->Add(); $NewContact->{FirstName}=$name; $NewContact->{LastName}="Charbeneau"; $NewContact->Save(); print "Added $name\n"; }

And this to delete the names I don't like:

$Contacts = $NameSpace->Folders("Personal Folders")->Folders("Contact +s")->{Items}; my $Cacharbes = $Contacts->Find("[LastName]=Charbeneau"); my $cnt = 0; while (1) { if ($Cacharbes->{FirstName} eq "Chuckles"){ $Cacharbes->Delete(); } $Cacharbes = $Contacts->FindNext() || last; }

The thing is, the find and find next function only return a single item from the main collection.

Each item in a Contacts folder collection has a unique ->{EntryID} property, but it's not something you can remmber off the top of your head.

C-.

Replies are listed 'Best First'.
Re: Re:(4)What do you want to delete?
by Anonymous Monk on May 29, 2002 at 20:32 UTC
    This is very good - however what happens if Charbeneau does not exist in the contacts file. Can I do some sort of Last Name = C* to get to the beginning of the C's and then FindNext or how the the error condition be handled if there is not match. What I am attempting to do is allow my cgi to update this contacts file from our intranet. Thanks.
      I would replace the complete last name with this:
      my $Cacharbes = $Contacts->Find("[LastName]>C and[LastName]<D ");

      C-.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-16 15:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found