in reply to Re^5: Outlook email with table
in thread Outlook email with table

Hey I decided to take another route based on my limited knowledge, which I used for the excel part of it. I think I have most of the code to do what I want. All I really need to know is how to copy from Excel and paste into Outlook, I know I am able to send email using outlook. Could you help me with just the pasting into outlook? Below is the code I am using. I just dont know how to paste it into the body of an outlook email. Thanks.
use Win32::OLE; use Win32::OLE qw/in with/; use Win32::OLE::Const 'Microsoft Excel'; use strict; use warnings; # Die on errors in Excel $Win32::OLE::Warn = 3; # Creates Excel Object my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); $Excel -> {"Visible"} = 0; # Doesnt allow any popups within Excel $Excel -> {"DisplayAlerts"} = 0; # Change path to where your files are located # Opens main Excel file and Center file my $Book2 = $Excel->Workbooks->Open('C:\TEST\Gold Report.xls'); # copy $Book2->Worksheets(1)->Range("A2:G2")->Copy; # This paste it into a different worksheet or workbook # How would I use this logic to paste it into the # body of my outlook email? $Book2->Worksheets(6)->Range("A2:G2")->PasteSpecial; $mail = new Win32::OLE('Outlook.Application'); $mail->{'Visible'} = 1; $item = $mail->CreateItem(0); $item->{'Subject'} = "This is a test"; $item->{'To'} = "image13\@gmail.com"; # I need to be able to paste it here $item->{'Body'} = "Here is the meat of the message TEST"; $item->Send(); #$mail->Quit();

Replies are listed 'Best First'.
Re^7: Outlook email with table
by marto (Cardinal) on Jan 25, 2011 at 10:27 UTC

    I've hardly used Win32::OLE, I'd suggest following the advice in the documentation which suggests referring to the Object Model documentation for the Microsoft Office application in question. It's important to understand what Win32::OLE is, and how to use it. If I were given this task, like your previous question, I'd avoid using Win32::OLE to automate other applications. As previously suggested, I'd use a combination of MIME::Lite and Spreadsheet::ParseExcel.