jamiros has asked for the wisdom of the Perl Monks concerning the following question:

My question is simple, I want to read a line from a Word doc and print it. The stuff I need runs from Ln 39 Col 43 to Ln 39 Col 46. I have tried everything and I have been searching the web for days... please help! =D

Here is the code I have so far:
use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; $file = "c:\\C-212\\200539061_D.doc"; $new_file = "c:\\C-212\\200539061_D.txt"; $WordObj = Win32::OLE->new('Word.Application', 'Quit') or die "Couldn' +t run Word"; $wd = $WordObj->Documents->Open($file); $WordObj->ActiveDocument->SaveAs({ FileName => $new_file, FileFormat =>wdFormatText, }); $wd->Close(); $WordObj->exit;

Replies are listed 'Best First'.
Re: MS Word and PERL
by terra incognita (Pilgrim) on Oct 05, 2005 at 20:02 UTC
    You should take a look at 469134, it will get you started with what you want to do.

    UPDATE

    When searching you may want to add 3989 to your list of places to look. Super Search has saved me more times than I can count (at least with out taking off my socks).

      Thanks for the search tip!! Works like a charm =D
Re: MS Word and PERL
by davidrw (Prior) on Oct 05, 2005 at 20:11 UTC
    Besides the thread Extract Single Line of Text from Word Document Using OLE that terra incognita, also keep in mind a very useful technique for this kind of this is to record a macro in Word of the task you want done, and view source on the macro. Then just translate the vb code into perl code ... it also a very quick way to reveal the relevant properties/methods.
Re: MS Word and PERL
by InfiniteSilence (Curate) on Oct 05, 2005 at 20:18 UTC
    After you have done the other things mentioned by responders, you might try:

    #!/usr/bin/perl -w use strict; use Win32::OLE; my $file = "c:\\temp\\foo.doc"; my $new_file = "c:\\temp\\foo2.doc"; #my $WordObj = Win32::OLE->new('Word.Application', 'Quit') or die "Cou +ldn't run Word"; my $WordObj = Win32::OLE->CreateObject(qq|Word.Application|) or die $! +; my $wd = $WordObj->Documents->Open($file); $WordObj->{Visible} = 1; $WordObj->Selection->MoveDown(5,17); #lines $WordObj->Selection->MoveRight(1,6); #column 1;
    MoveDown and MoveRight's first parameters correspond to some constants in Word -- wdLine and wdCharacter or something like that.

    Celebrate Intellectual Diversity