in reply to Re: Outlook MailItem Body Question
in thread Outlook MailItem Body Question
Right... I've messed about in Perl and VBScrip this morning and my findings are this... I can do what you want in VB but not in Perl. Weird... (Outlook97, btw).
#!C:/ActivePerl/bin/perl.exe use strict; use warnings; use Win32::OLE; #Tset case - I know the app is running... my $Outlook = Win32::OLE->GetActiveObject("Outlook.Application"); my ($MAPI,$Inbox,$TestFolder,$Message,$bodytext,$newtext); $MAPI=$Outlook->GetNameSpace("MAPI"); $Inbox=$MAPI->GetDefaultFolder(6); $TestFolder=$Inbox->Folders("Perlmonks"); print "There are " . $TestFolder->{Items}->{Count} . " items in the in +box.\n\n"; for my $x (1) { $bodytext = $TestFolder->Items($x)->Body; print "Message Subject:\n" . $TestFolder->Items($x)->Subject . "\n +"; print "Body Text:\n$bodytext\n"; print "Replacing entire body with \"foo bar\"\n\n"; $TestFolder->Items($x)->{'Body'} = "foo bar"; #Doesn't work.. $TestFolder->Items($x)->LetProperty('Body',"foo bar") ; #Does't wo +rk.. $TestFolder->Items($x)->Save; #Doesn't make a difference! print "Body is now supposedly:\n\n" .$TestFolder->Items($x)->Body +. "\n"; #Hasn't updated! my $NewItem = $TestFolder->Items($x)->Copy; #Works fine }
And in VBScript...
'..snip... For Each M In objInbox.Items Text = Text & M.Subject & vbCr x=x+1 M.Body= "foo bar" 'Assignment msgbox M.Body 'Works perfectly M.Save Next '..snip...
I'm no expert but I couldn't get the SetProperty(property,@args,value) syntax to work in Win32::OLE... perhaps it's a bug? The VBScript/Automation of Outlook97 is pretty shoddy at the best of times. Outlook89 and above have VBA (rather than VBScript) automation, AFAIK, tho...
|
|---|