Update...sometimes you just need to write it down to figure it out!! I just replaced $bookmark->{Name} with Testbookmark and it worked so now I can carry on, thanks anyway Monks!

I'm very new to perl however have already used it to do some very cool text manipulation and finding it very powerful so far, keen to learn more.

I've been struggling for a long while trying to figure this out and I can't find any exact examples.

I've got about 50 word documents to update with the same fields over and over so I want to automate the process.

I have a standard output file which I'm going to read data from then paste into a Word document at the appropriate places.

I've set up a Word doc as a template with Bookmarks in it in the areas I need to update.

I have a script that can open the word document, the part I am struggling with is how to move the cursor to a specific bookmark location in the word doc. I have called the bookmark Testbookmark.

I think I'm going to need to do something like

$document->ActiveWindow->Selection -> GoTo(wdGoToBookmark, 0, 0, $bookmark->{Name}); But I'm not sure how to specify the $bookmark->{Name} section.

Would really appreciate some help. :)

So far I have:

use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $ObjectClass = "Word.Application"; my $File2 = "c:\\_test\\templateOUT.docx"; my $Word = Win32::OLE->GetActiveObject($ObjectClass) || Win32::OLE->new($ObjectClass, 'Quit'); $Word->{'Visible'} = 1; $Word->Documents->Open("C:\\_test\\template.docx") || die("Unable to o +pen template document ", Win32::OLE->LastError()); my $document = $Word->ActiveDocument; # selection is the insertion point. my $selection = $Word->Selection; my $mytxt = "Comment Text"; $Word->Selection->TypeText ({Text => $mytxt}); $Word->ActiveDocument->SaveAs({FileName => $File2}); $Word->Quit();

In reply to How to move to a bookmark in a MS Word document? by dominicb

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.