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; }
In reply to Word OLE add Comments by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |