Trying to extract Headings from a Word 2003 document using Perl

K

kleefaj

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.

By the way, when I assign the return value of the
GetCrossReferenceItems to a scalar (instead of an array) I get the
following output:

ARRAY(0x1bfc7a8)Done!

Any thoughts?

-Jeff
 
M

Mumia W. (on aioe)

[...]
By the way, when I assign the return value of the
GetCrossReferenceItems to a scalar (instead of an array) I get the
following output:

ARRAY(0x1bfc7a8)Done!

Any thoughts?

-Jeff

It's time for you to (re)read "perldoc perlref"

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

kleefaj

Mumia said:
It's time for you to (re)read "perldoc perlref"

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

Excellent!! That was it!

Thanks,
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,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top