jab43 has asked for the wisdom of the Perl Monks concerning the following question:

In a word document I have tables and some of them have lines of text after them. So it goes tables, lines of text, table etc. I can select the table fine with:

my $table = $word->ActiveDocument->Tables(2); $table->Select();

What I need to do is select the table and select a number of line after the table. I am doing this so I can use Word's keepWithNext feature so the entire table and lines are on the same page.

I have ran some macros in word and have been looking at MoveDown and MoveUp. Neither of these can I get to work. I'm given this pattern in VBA:

Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.MoveDown

If I try to use wdLine it says "bareword 'wdline' not allowed." With either of these lines:

$word->selection->MoveDown({Unit => wdline,Count=>1,Extend=> wdExtend, +}); $word->selection->MoveDown(wdLine,1);

Is there a better way to do what I want or can you help me get the correct format using MoveDown. Thanks!

Replies are listed 'Best First'.
Re: Microsoft Word - Select next line after a table
by nevdka (Pilgrim) on Aug 06, 2013 at 22:59 UTC

    Did you use wdline or wdLine? Capitalization makes a difference...

    If that's not the problem, you should be able to take care of the bareword error by using quote marks - 'wdLine' and 'wdExtend'. I'm not familiar with controlling Word with Perl, so this is about as much help as I can give.

      I got the error removed with your suggestion but it still doesn't do anything.

      So is there another way to select a line or maybe a paragraph? I'm open to any way, using Perl of course.

        This works, but I don't know why:

        $word->Selection->MoveDown({Extend=> 1, Count=> 1});

        Keep in mind that there might be a blank line after your table, so set Count appropriately. It looks like OLE wants a number, rather than 'wdExtend'. Which is weird, but what would you expect from a mashup of Microsoft and open source?

        Update: Following on from Anonymous Monk's advice, putting use Win32::OLE::Const 'Microsoft Word'; at the top of the file fixes this. This works:

        $word->Selection->MoveDown({Extend=> wdExtend, Count=> 1});