Trying to extract Headings from a Word 2003 document using Perl

K

kleefaj

Greetings.

I'm trying to extract the Headings from a Word 2003 document using
Perl. The VBA version of this script works.

Here's the script:
==============================
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

my $Word = Win32::OLE->new('Word.Application', 'Quit');
$Word->Documents->Open("C:\\mydoc.doc") || die("Unable to open document
", Win32::OLE->LastError());

my @i =
$Word->ActiveDocument->GetCrossReferenceItems(wdRefTypeHeading);
foreach (@i) {
# print "$_\n";
print "got one!\n";
}
$Word->Quit;
print "Done!\n";
==============================

This line

$Word->ActiveDocument->GetCrossReferenceItems(wdRefTypeHeading)

should return an array of strings. It works in VBA. I commented out

print "$_\n";

so I could see if the loop runs at all. My output is

got one!
Done!

but I'm expecting to see "got one!" about twenty times. I figure it has
something to do with the way I'm loading the array.

Any thoughts?

-Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top