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

Hail Monks!

Is there a Select All method for MS Word OLE in Perl?
The reason I ask is this:
use strict; use Win32::OLE; my $MSWord = Win32::OLE->new('Word.Application') or die "Can't get word!:$!\n"; my $doc1 = shift || die "You must specify two word docs\n"; my $doc2 = shift || die "You must specify two word docs\n"; my $docOut = shift || die "You must specify an Output doc\n"; my $WordDoc1 = $MSWord->Documents->Open($doc1) or die "Could not open $doc1\n"; my $WordDoc2 = $MSWord->Documents->Open($doc2) or die "Could not open $doc2\n"; my $WordDocOut = $MSWord->Documents->Open($docOut); print "opened bigdoc.doc\n"; ### ### HERE's my BUG please help :) ### my $select1=$WordDoc1->SelectAll() or die "Could not do SelectAll() on doc1\n"; $select1->Copy(); print "did select all on doc1\n"; $WordDocOut->Paste(); print "did paste\n"; $WordDoc2->SelectAll()->Copy(); print "did select all on doc2\n"; $WordDocOut->Paste(); print "did paste\n"; $WordDocOut->Save(); END { $WordDoc1->Close(); $WordDoc2->Close(); $MSWord->Quit(); }
Results in this output:
C:\>catword.pl c:\LINKS.doc c:\TAOandWebServices.doc c:\out.doc
opened bigdoc.doc
Could not do SelectAll() on doc1
I guess there is no SelectAll method ???
But I don't know what to do instead. :(
I already know about:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/off2000/html/wotocobjectmodelapplication.asp
with many ++'s to meetraz who has been good enough to get me this far.

Replies are listed 'Best First'.
Re: How do I Selecting All in a MSWord doc?
by Mr. Muskrat (Canon) on Jan 24, 2003 at 23:34 UTC

    You might want to check out the review of Win32::OLE for one way to get all the text of a Word document.

    Update: By the way, you should look at an MS Word macro that selects all the text... you will find that it doesn't use SelectAll().

      Hi Mr. Mushrat,
      Don't tell me I can only select text! I want to be able to get everything.
      You know, drawings, formating, comments, table of contents, all that stuff.
      Can it be done in Perl?
        I'm sure that it can. I read your question as "how do I select all of the text" instead of "how do I select everything". Create yourself an MS Word macro that selects everything in an MS Word doc and then view the code of the macro. It will give you the information you seek.
Re: How do I Selecting All in a MSWord doc?
by Zero_Flop (Pilgrim) on Jan 25, 2003 at 05:53 UTC

    to select all you the OLE is "Selection.WholeStory" or perlish Selection->WholeStory

    v
      Better yet check this out

      http://perlmonks.thepen.com/113635.html