Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re(5): Creating entries in an Outlook Calendar

by dmmiller2k (Chaplain)
on Apr 22, 2002 at 14:21 UTC ( #161064=note: print w/replies, xml ) Need Help??

in reply to Re: Re(3): Creating entries in an Outlook Calendar
in thread Creating entries in an Outlook Calendar

If you haven't already, take a look at the article I referenced in my earlier message. You should also view the Win32::OLE docs.

The short answer is that once you have the 'folders' object (or any collection), you can index it like an array. To wit:

# from your own example my $outlook = new Win32::OLE('Outlook.Application'); my $ns = $outlook->GetNameSpace("MAPI") or die "can't open MAPI namesp +ace\n"; my $folders = $ns->Folders(); # get the folders collection foreach my $folder (in @$folders) { # here $folder will be set to each folder in turn }

Hope this helps ..


If you GIVE a man a fish you feed him for a day
TEACH him to fish and you feed him for a lifetime

Replies are listed 'Best First'.
Re: Re(5): Creating entries in an Outlook Calendar
by lumina (Novice) on Apr 23, 2002 at 08:48 UTC
    Thanks guys, and humble apologies for being such a nugget. I had my personal options for set to the default of three levels, so I couldn't see that you had replied. It's sorted now, so am off and running again. duh!

    I had already managed to get a list of the folders at the top level using code similar to what you suggested namely
    my $Folder = $namespace->Folders("Personal Folders"); my $Items = $Folder->Items; my $sheetcnt = $namespace->Folders->Count(); foreach (1..$sheetcnt){ $Folder = $namespace->Folders($_)->{Name}; print "\t" .$Folder ."\n"; # my $subfolder = $namespace->Folders($Folder)->MAPIFolder->Count(); # foreach (1..$subfolder){ # print "\t" .$namespace->Folders($Folder)->MAPIFolder($_)->{Name +}. "\n"; # } }

    The commented out lines are my attempt to get to the next level down, which should be the list of folders, including inbox, outbox, calendar etc. etc. however if the commented out code is reinstated, it fails. with 'Can't call method "Count" on an undefined value at .......' which is the line
    my $subfolder = $namespace->Folders($Folder)->MAPIFolder->Count();
    Having checked the Outlook Object Model from the reference helpfully supplied by this site, MAPIFolder does seem to be the next level down, so I am not sure where I am going wrong.
    Any ideas?

      It should be even simpler:

      my @folder_names = (); my %folder_contents = (); my $folders_collection = $namespace->Folders(); foreach my $folder (in( $folders )) { my $folder_name = $folder->{Name}; my $folder_items = $folder->Items(); push @folder_names, $folder_name; $folder_contents{$folder_name} = []; foreach my $item (in( $folder_items )) { push @$folder_contents{$folder_name}, $item->{Name}; } }


      If you GIVE a man a fish you feed him for a day
      TEACH him to fish and you feed him for a lifetime
      Progress!!! With a little bit of guess work, and adding the suggestions from this board, I have managed to get a rotine which now happily reads round all the folders and subfolders in my Outlook.

      use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; use Win32::OLE::Variant; use Time::Local; use POSIX; #open the Outlook program my $outlook; eval { $outlook = Win32::OLE->GetActiveObject('Outlook.Application') }; if ($@ || !defined($outlook)) { $outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;} +) or die "oops\n"; } my $namespace = $outlook->GetNameSpace("MAPI") or die "can't open MAPI + namespace\n"; my $Folder; my $subfoldernm = "Calendar"; my $sheetcnt = $namespace->Folders->Count(); foreach (1..$sheetcnt){ $Folder = $namespace->Folders($_)->{Name}; print "\n\t No.". $_ ." Folder Name - >" .$Folder ."<\n"; print "\n\t\tNo.\tItems\tItems"; my $subfldrcnt = $namespace->Folders($Folder)->Folders()->Count or +my $dummy = "true"; foreach (1..$subfldrcnt){ my $subfolder = $namespace->Folders($Folder)->Folders($_)->{Nam +e} or die "cant access folder $Folder"; my $itemcnt = $namespace->Folders($Folder)->Folders($subfolder) +->Items()->Count or my $empty = "true"; print "\n\t\t$_\t$itemcnt\t$subfolder"; } }
      I now need to work out how to store a calendar entry away. I guess this means a two part task. Firstly to "select" the correct calendar folder to store the entry in, secondly to generate the entries to store away.

      From the results of my current routine, I can see that for testing purposes, the folder I need is "Personal Folders" and the subfolder is "Calendar"

      I'm thinking that some code along the lines of :-
      my $cal = new Win32::OLE('Outlook.Application'); $cal->{'Visible'} = 1; my $item = $cal->CreateItem(0); $item->{'Subject'} = "perl test"; $item->{'Location'} = "Test Location"; $item->{'Start'} = "04/30/2002 12:00"; $item->{'End'} = "04/30/2002 12:30"; my $selectfolder = $namespace->Folders($Folder)->Folders($subfo +lder)->Items()->Add($item) or " **** can't add item";

      but I suspect this is only the half of it.

      As before, does anyone have any ideas?

      I did find some code to generate an e-mail entry, and am thinking that the code to generate a calendar entry wouldn't be that dissimilar.
      #my $mail = new Win32::OLE('Outlook.Application'); #$mail->{'Visible'} = 1; #my $item = $mail->CreateItem(0); #$item->{'Subject'} = "This is a test"; #$item->{'To'} = "david.booth\"; #$item->{'Body'} = "Here is the meat of the message"; #$item->Send(); #$mail->Quit();

      As ever any suggestions as to how best doing this will be most gratefully received

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2023-09-23 17:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found