title: How to Extract text from MS Word?
body: <p>I'm trying to open a word document and just extract all the text that is in the document and display it to the user using <a href="http://search.cpan.org/%7Ejdb/Win32-OLE-0.1709/lib/Win32/OLE.pm" rel="nofollow noreferrer">Win32::OLE</a></p>
  <pre><code>#usr/bin/perl
  #OLEWord.pl
  
  #Use string and print warnings
  use strict;use warnings;
  #Using OLE + OLE constants for Variants and OLE enumeration for Enumerations
  use Win32::OLE;
  use Win32::OLE::Const 'Microsoft Word';
  
  $Win32::OLE::Warn = 3;
  
  #set the file to be opened
  my $file = '/work/Test.docx';
  
  #Create a new instance of Win32::OLE for the Word application, die if could not open the application
  my $MSWord = Win32::OLE-&gt;new('Word.Application','Quit') and &quot;Opened Word&quot; or die     &quot;Unable to open document &quot;, Win32::OLE-&gt;LastError(); 
  #Set the screen to Visible, so that you can see what is going on
  $MSWord-&gt;{'Visible'} = 1;
  #open the request file or die and print warning message
  my $Doc = $MSWord-&gt;Documents-&gt;Open('C:\work\Test.docx') or die &quot;Could not open &quot;, $file, &quot; Error:&quot;, Win32::OLE-&gt;LastError();
  
  #$MSWord-&gt;ActiveDocument-&gt;SaveAs({Filename =&gt; 'AlteredTest.docx', 
                              #FileFormat =&gt; wdFormatDocument});
                              
                              
  sub ShowObjs {
  my $obj = shift;
  foreach (sort keys %$obj) {
  print &quot;Keys: $_ - $obj-&gt;{$_}\n&quot;; }
   }
  
   my $paragraphs = $Doc-&gt;Paragraphs;
   ShowObjs($paragraphs);
  
   #  Get and print the Text inside the opened file
   my $paragraphs = $Doc-&gt;Paragraphs;
   my $txt = $Doc-&gt;Range-&gt;Text;
   print $txt;
                              
   $MSWord-&gt;ActiveDocument-&gt;Close;
   $MSWord-&gt;Quit;
  </code></pre>
  <p>I'm getting this error code:</p>
  <blockquote>
  <p>OLE exception from &quot;Microsoft Word&quot;:</p>
  <p>Command Failed</p>
  <p>Win32::OLE(0.1709) error ox800a1066
  in METHOD/PROPERTYGET &quot;Open&quot; at OLEWord.pl line 20</p>
  </blockquote>
  <p><strong>Update:</strong> I can open up the Word application fine, it's just when I try to open up the file that is the problem</p>