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

When I run the below program the MS Word Program also opens. How to avoid that ?

use strict; use Win32::OLE; use Win32::OLE::Enum; parseAndScanWord($filename); sub parseAndScanWord { my ($fileName) = @_; my $document = Win32::OLE -> GetObject($fileName) or return; my $paragraphs = $document->Paragraphs(); my $enumerate = new Win32::OLE::Enum($paragraphs); while(defined(my $paragraph = $enumerate->Next())) { $text = $paragraph->{Range}->{Text}; } }

Replies are listed 'Best First'.
Re: Parsing MSWord File
by Corion (Patriarch) on Oct 02, 2008 at 12:41 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Parsing MSWord File
by jplindstrom (Monsignor) on Oct 02, 2008 at 13:30 UTC
    On a general note, keep the task manager open and look for MS Word processes not being terminated properly if your script is Ctr-C:ed, or exit()-ed without the Win32::OLE object being destroyed.

    That may also be the reason if you have problems opening/saving Word documents for no reason -- there is another process still alive with the document open.

    /J

      I did like this but no effect :-

      my $document = Win32::OLE -> GetObject($doc,sub {$_[0]->Quit;});
Re: Parsing MSWord File
by GrandFather (Saint) on Oct 06, 2008 at 23:56 UTC
    $document->{Visible} = 0;

    How can you write the sample code you gave, yet not understand how to set a property on an object nor understand what False is?


    Perl reduces RSI - it saves typing
      The code is downloaded.

        This is not how programming works, at least not here. We expect you to do your own work, to do your own research and to learn the language instead of asking us all the time to do your work for you.