Microsoft Word and Perl

I

Ilaiyarasan

I have been trying to update my word document using perl, i used

$word->Selection->WholeStory;
$word->Selection->Fields->{Update};


But this is a little slow and at times doesnot update completely. I
modified the code and right now getting a wired error but the same in
VBA works really well .


my $newdoc = $word->ActiveDocument;
foreach my $obj_Story ($newdoc->StoryRanges ){
$obj_Story->Fields->{Update}; ==> Cannot find object
while ($obj_Story->NextStoryrange != ""){
$obj_Story = $obj_Story->NextStoryRange;
$obj_Story->Fields->{Update}; ==> Cannot find object
}

}


The equivalent in VBA is ..

Dim obj_Story As Range
For Each obj_Story In ActiveDocument.StoryRanges
obj_Story.Fields.update
While Not (obj_Story.NextStoryRange Is Nothing)
Set obj_Story = obj_Story.NextStoryRange
obj_Story.Fields.update
Wend
Next obj_Story
Set obj_Story = Nothing



Could someone tell me where am i going on.


Ilaiy
 
B

Ben Morrow

Quoth (e-mail address removed) (Ilaiyarasan):
I have been trying to update my word document using perl, i used

$word->Selection->WholeStory;
$word->Selection->Fields->{Update};

But this is a little slow and at times doesnot update completely. I
modified the code and right now getting a wired error but the same in
VBA works really well .

my $newdoc = $word->ActiveDocument;
foreach my $obj_Story ($newdoc->StoryRanges ){
$obj_Story->Fields->{Update}; ==> Cannot find object

I don't know much about OLE, but surely that should be

$obj_Story->Fields->update;

? update is a method, not a property.
while ($obj_Story->NextStoryrange != ""){
^^
R, surely?
$obj_Story = $obj_Story->NextStoryRange;
$obj_Story->Fields->{Update}; ==> Cannot find object
}

I would write that loop the other way round:

$obj_Story->Fields->update
while $obj_Story = $obj_Story->NextStoryRange;

That way you don't need the extra statement before the loop.
The equivalent in VBA is ..

Dim obj_Story As Range
For Each obj_Story In ActiveDocument.StoryRanges
obj_Story.Fields.update
While Not (obj_Story.NextStoryRange Is Nothing)
Set obj_Story = obj_Story.NextStoryRange
obj_Story.Fields.update
Wend
Next obj_Story
Set obj_Story = Nothing

Ben
 
I

Ilaiyarasan

I think it still gives me a problem

my $newdoc = $word->ActiveDocument;
foreach my $obj_Story ($newdoc->StoryRanges ){
$obj_Story->Fields->Update;
while (my $obj_Story = $obj_Story->NextStoryRange){
$obj_Story->Fields->Update;
}

It srill gave me the same error i am not sure why it is doing that
because it works perfectly in VB but when you get the same code in
Perl it kind of acts really stange..

Ilaiy
 
B

Ben Morrow

[stop top-posting]

Quoth (e-mail address removed) (Ilaiyarasan):^^
lower case 'u'
I think it still gives me a problem

my $newdoc = $word->ActiveDocument;
foreach my $obj_Story ($newdoc->StoryRanges ){
$obj_Story->Fields->Update;
^^
upper case 'U'
while (my $obj_Story = $obj_Story->NextStoryRange){
$obj_Story->Fields->Update;
}

It srill gave me the same error i am not sure why it is doing that
because it works perfectly in VB but when you get the same code in
Perl it kind of acts really stange..

Be more careful.

If this is not the problem, please post your code and the *exact* error
message you get.

Ben
 
I

Ilaiyarasan

The error which i get is

Win32::OLE(0.1502) error 0x80020005: " Type mismatch" in
METHOD/PROPERTYGET" argumrnt 1 at test1.pl line 37 which is the
$obj_Story->Fields->Update


Could you tell me what is the problem

Ilaiy











Ben Morrow said:
[stop top-posting]

Quoth (e-mail address removed) (Ilaiyarasan):^^
lower case 'u'
I think it still gives me a problem

my $newdoc = $word->ActiveDocument;
foreach my $obj_Story ($newdoc->StoryRanges ){
$obj_Story->Fields->Update;
^^
upper case 'U'
while (my $obj_Story = $obj_Story->NextStoryRange){
$obj_Story->Fields->Update;
}

It srill gave me the same error i am not sure why it is doing that
because it works perfectly in VB but when you get the same code in
Perl it kind of acts really stange..

Be more careful.

If this is not the problem, please post your code and the *exact* error
message you get.

Ben
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top