Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I know that my question is not so relevant for Perl, but I really can't find any other information on the Web, so I hope to fine a monk wanting to help me out.
I need to insert in a Word document comments for words matching a RegExp. So far I put together the following script which is working fine. It highlight all instances of that word in the document. What I'd like to do is to add a comment for that words. I don't find any info for that. Can you point me to the right direction?
#!/usr/bin/perl use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 3; my $word = get_word(); $word->{Visible} = 1; my $doc=$word->Documents->Open('D:/test.docx'); my $WordToLookup="xy"; FindAndReplace(); sub FindAndReplace{ $word->Selection->HomeKey(wdStory); $word->Selection->Find->{'Text'}=$WordToLookup; $word->Selection->Find->Replacement->{'Highlight'}=1; $word->Selection->Find->Execute({Replace=>wdReplaceAll}); } sub get_word { my $word; eval { $word = Win32::OLE->GetActiveObject('Word.Application'); }; die "$@\n" if $@; unless(defined $word) { $word = Win32::OLE->new('Word.Application', sub { $_[0]->Quit +}) or die "Oops, cannot start Word: ", Win32::OLE->LastError, "\n"; } return $word; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Word OLE add Comments
by Corion (Patriarch) on Oct 23, 2014 at 17:09 UTC | |
|
Re: Word OLE add Comments
by poj (Abbot) on Oct 23, 2014 at 18:56 UTC | |
|
Re: Word OLE add Comments
by perlron (Pilgrim) on Oct 24, 2014 at 00:00 UTC | |
by opitzs (Sexton) on Oct 24, 2014 at 09:55 UTC |