Hi, Below is the tried code.
#use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft.Word'; # wd constants use Win32::OLE: +:Const 'Microsoft Office'; # mso constants use Win32::OLE::Const 'Microsoft Office'; # -------------------------------------------------- my($input_file) = 'C:\Documents and settings\Jake\Desktop\oledoc.do +c'; $input_file= Win32::GetCwd() . "/$input_file" if $input_file !~ /^(\w: +)?[\/\\]/; die "File $input_file does not exist" unless -f $input_file; my($word)= Win32::OLE->new('Word.Application', 'Quit') || die "Couldn' +t run Word"; my($doc)= $word->Documents->Open($input_file); print "Extract using first method: \n"; #Select the first paragraph my $sel = $word->ActiveDocument->Paragraphs(1)->range->Select; my $myrange = $word->Selection->Range; # Insert the string before the first paragraph $word->Selection->InsertBefore("Beforenewstuff"); print "Range is $myrange\n"; #Then insert the image $myrange->InlineShapes->AddPicture('C:\Documents and Settings\Jake\Des +ktop\Charts1.gif',false,true); $myrange->Collapse ({Direction => wdCollapseEnd}); #Search for 'Addimagehere' in the document $doc->Selection->{Text}="willbereplaced"; $doc->Selection->Collapse(); #Insert the test and gif next to it. This part doesn't work as intende +d $doc->Selection->InlineShapes->AddPicture ('C:\Documents and Settings\ +Jake\Desktop\Charts1.gif', false, true); $word->Selection->Collapse (wdCollapseEnd); # close the document and the application unlink $input_file if -f $input_file; $doc->Close; $word->Quit(); exit(0);
I am trying to locate 'addimagehere' in the document and to replace it with chart1.gif.

In reply to Re^3: Finding a text and replace it with image by Anonymous Monk
in thread Finding a text and replace it with image by jnirmal

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.