Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How To goto End of Word doc

by fishpoem (Initiate)
on Feb 02, 2017 at 03:57 UTC ( #1180811=perlquestion: print w/replies, xml ) Need Help??

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

Question: how do I go to the END of a Word doc before CLOSE?

The code below simply appends one document to another. I would like to go to the very end of the destination document AFTER the text has been appended but BEFORE closing the destination document.

$Word->Documents->open( $source_doc ) or die "Unable to open $source_doc ", Win32::OLE->LastError(); my $text = $Word->ActiveDocument->Content->Text; $Word->ActiveDocument->Close; $Word->Documents->open( $dest_doc ) or die "Unable to open $dest_doc ", Win32::OLE->LastError(); $Word->ActiveDocument->Content->InsertAfter({ Text => $text }); $Word->ActiveDocument->Close;

Replies are listed 'Best First'.
Re: How To goto End of Word doc
by poj (Abbot) on Feb 02, 2017 at 07:37 UTC
    $Word->Selection->EndKey( { Unit => 6 } ); # wdStory = 6 $Word->ActiveDocument->Close;
    poj

      Here are some MSDN documentation links (assume Word ≥2013 unless noted) to the various objects and methods and enumerations mentioned in ++poj's post:

        Thank you for taking the time and trouble to provide such a bounty of useful information. And quickly, too! The replies people have given totally amaze me. I just joined up and didn't know if I'd get ANY responses. This has been great.
      Thank you for responding so quickly! Quite amazing, actually. Really appreciate the code snippet. I'd tried EndKey previously, but hadn't formatted it properly. I'll try again.
Re: How To goto End of Word doc
by GotToBTru (Prior) on Feb 02, 2017 at 06:42 UTC

    Please use code tags, it is very hard to read your post.

    Do you know how to go to the end using OLE? I believe that is the material question here. An OLE site might be more useful to you than a Perl site to answer that.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

      Thank you for responding so quickly! I need to find out what "code tags" are.

        Reply to this node. Look immediately above the text box. It describes two kinds of tags, paragraph and code. Use the preview button below to experiment with their effects. Repeat until it looks right, then click on the create button. You can edit previously created posts, but there is no preview mode, you must have to keep re-submitting. You'll get it eventually, and you will find well formatted posts get quicker answers.

        But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: How To goto End of Word doc
by Anonymous Monk on Feb 02, 2017 at 07:27 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1180811]
Approved by Erez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2020-10-25 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (249 votes). Check out past polls.

    Notices?