vishnu.h has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I have the following sub-routine which copies a given range frrom microsft excel and pastes it in the body of microsoft outlook mail. Somehow copy is happening but the paste doesnt happen. could someone please guide me???

sub send_weekly { my $Outlook = Win32::OLE->GetActiveObject ('Outlook.Application') || Win32::OLE->new('Outlook.Application'); my $Outlook = new Win32::OLE('Outlook.Application'); $excel_ob = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $excel_ob->{Visible} = 0; $excel_ob->{DisplayAlerts}=0; $excel_sheet_name = $day."-".$month."-".($yr19+1900); $dir = getcwd(); $temp = File::Spec->catfile("$dir","Weekly-Report-Vishnu.xlsx"); + $weekly_report_wb = $excel_ob->Workbooks->Open($temp) or die "Coul +d not open Weekly sheet $!"; $weekly_report_ws = $weekly_report_wb->Worksheets($excel_sheet_nam +e) or die "Couldn't open Weekly Report $!\n "; $weekly_report_ws->Range("A1:H26")->Copy; # Create Mail Item my $item = $Outlook->CreateItem(0); # 0 = mail item. unless ($item) { die "Outlook is not running, cannot send mail.\n"; } $item->{'Subject'} = $subject; $item->{'To'} = $to; #$weekly_report_ws->Range("A1:H26")->Copy; $item->{'Body'}= $item->PasteSpecial($weekly_report_ws->Range("A1: +H26")->Copy); $item->{'From'} = $from; $item->{'Cc'} = $cc; # 2=high, 1=normal, 0=low $item->{'Importance'} = $priority ; # Send the Email $item->Send(); }

Replies are listed 'Best First'.
Re: OLE module
by marto (Cardinal) on May 09, 2011 at 10:11 UTC

    Check the Message format (Options->Mail Format->Message Format) in Outlook. 'Paste Special' isn't an option for 'Plan Text' formatted emails. Failing that don't disable DisplayAlerts, read the module documentation and Using OLE with Perl for other debugging/error checking advice.

Re: OLE module
by Anonymous Monk on May 09, 2011 at 10:05 UTC