This snippet here reads an open word document and is really useful if you want to have a "live" word retrieval. It retrieves whatever's typed in the document, as well as the document's filename and its properties.
I wrote this code to find out what the current user was doing with Word and to provide him with information related ot what he'd typed.
package readWord; use strict; use Win32::OLE qw(in with); require Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = qw(readActiveDoc); sub readActiveDoc # this method returns the name of the active document and 2 hashes con +taining every single # word found in the document and all the document's properties. Hence +it is ready for use { if ( my $word = Win32::OLE->GetActiveObject('Word.Application'))# c +onnect to word document { if ($word->Documents->Count()) # makes sure at least one documen +t is open { # next line for debug only # print "\nSuccessfully connected to existing word"; my $docName = $word->ActiveDocument->Name; # retrieve name my $docProperties = $word->ActiveDocument->{BuiltInDocumentPr +operties}; my $wordRange = $word->ActiveDocument->Content; return ($docName,$docProperties,$wordRange); } } return (undef,undef,undef); # if code reaches this line then it has +n't reached the other return } # implying either the program's not open or there' +s no document.

In reply to Reading data from an open Word Document by Foggy Bottoms

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.