Hi Monks

I am having trouble with OLE and inserting pictures into a word document. The problem lies in getting a picture into the document after a page break. The pictures insert easily onto the first page but I cannot get them onto the second page - probably due to my lack of knowledge in Object programming. I have also used code I have found on the web and do not claim to be the author of most of it ;-)

here is my code:

use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Variant; my $cur_style = 'a'; my $cur_bookmark = 'a'; my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; my $selection = $word->Selection; text ($document, "Page 1"); enter ($document); my $picture = insert_picture($document, 'C:\dee-dwive\pic1.jpg', 0, 1, + 0, 250); enter ($document); $selection ->InsertBreak(wdPageBreak); enter ($document); text ($document, "Page 2"); enter ($document); $picture = insert_picture($document, 'C:\dee-dwive\pic2.jpg', 0, 1, 0, + 250); enter ($document); save_doc_as($document, 'C:\dee-dwive\picture.doc'); #close_doc($document); #$word->Quit; sub text { my $document = shift; my $text = shift; $document->ActiveWindow->Selection -> TypeText($text); } sub enter { my $document = shift; $document->ActiveWindow->Selection -> TypeParagraph; } sub insert_picture { my $document = shift; my $file = shift; my $left = shift; my $top = shift; my $width = shift; my $height = shift; my $picture = $document-> Shapes -> AddPicture ( $file, $left, $top, $width, $height, ); return $picture; } sub insert_page_break { my $document = shift; $document->ActiveWindow->Selection->{Range} -> InsertBreak(wdPageBre +ak); }

Thanks for your helpful advice in advance

2006-05-05 Retitled by GrandFather, as per Monastery guidelines
Original title: 'OLE Problem'


In reply to MS word insert picture again by Secode

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.