Good day Monks. I am trying to locate highlighted words in a ms-word document and the page numbers on which they reside. I am having trouble getting the page number. I am trying it like this:
use Win32::OLE::Const 'Microsoft Word';
$filename = "c:\\work\\test.doc";
$word = Win32::OLE->new('Word.Application', 'Quit');
$doc = $word->Documents->Open($filename) or die "Can't open: $!\n";
for(my $i = 1; $i <= $doc->Words->Count; $i++) {
if($doc->Words->Item($i)->HighlightColorIndex > 0)
{
$page = $doc->Words->Item($i)->Application->Selection
+ ->Information(wdActiveEndPageNumber);
print "$page\n";
}
}
but when I run it on a file with one word highlighted on each of three pages, it returns 1 for the page number three times. Anyone know what I'm doing wrong?
TIA...Steve
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.