Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

When I'm creating a new note in outlook via OLE using the following code, everything works fine except I cannot figure out how you can set the note color. Retreiving the color value via $Note->Color, works but I seam unable to write it even though the Object Model shows it as a Property like the rest. Help!
use Win32::OLE; use Win32::OLE::Const; my $Body = "this is just a test\nnew note"; my $Color = 1; my $Categories = "Favorites"; my $MessageClass = "IPM.StickyNote"; my $Top = "182"; my $Width = "200"; my $Height = "166"; my $Left = "207"; $Outlook = Win32::OLE->GetActiveObject('Outlook.Application'); $olc = Win32::OLE::Const->Load($Outlook); # Setup Creation of a new Note $note = $Outlook->CreateItem($olc->{olNoteItem}); # Write Note Title & Body $note->{Body} = $Body; # Optional note properties. $note->{Categories} = $Categories; $note->{Width} = $Width; $note->{Height} = $Height; $note->{Top} = $Top; $note->{Left} = $Left; #$note->(Color) = $Color; # Close and Save note. $note->Close($olc->{olSave});
Jonny

Replies are listed 'Best First'.
Re: OLE and Outlook Note Color's
by simon.proctor (Vicar) on Mar 01, 2002 at 00:27 UTC
    The problem with your code is due to the lack of strict and warnings. If you had those turned on you would see that your call to set the colour is wrong:
    # $note->(Color) <--------wrong $note->{Color} = $Color;
    I tested it and was able to create a note of the colour blue just by changing that line :)
    Update: heres some working code. I tested it on Outlook 2000 on win2k using Activestate Perl
    use Win32::OLE; use strict; use warnings; use constant olBlue => 0; use constant olGreen => 1; use constant olPink => 2; use constant olWhite => 4; use constant olYellow => 3; use constant olSave => 0; my $options = { 'Body' => "Test note", 'Color' => olBlue, 'Categories' => "Favorites", 'MessageClass' => "IPM.StickyNote", }; my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application'); # Setup Creation of a new Note my $note = $Outlook->CreateItem(5); # Write Note Title & Body while (my ($key,$val) = each %{$options}) { $note->{$key} = $val; } # Close and Save note. $note->Close(olSave);
      Many thnks Simon, your code works perfectly. I'll be going through my code with strick & warning in future. Jonny (who's perl monks password still hasn't arrived)