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.
|