in reply to Word tables, OLE, perl, and me.

I have come across "MoveUp" and attempted to use it. This seems promising, but I think I'm not understanding the syntax or context I need to use it. My example:
my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{Visible} = 1; my $document = $word->Documents->Open('C:/temp/doctest.doc'); my $table = $word->ActiveDocument->Tables(2); my $selection = $table->Select; $selection->MoveUp(wdLine,1); my $str = $selection->Range(0,10)->{Text}; $table->Range->Copy; print qq{$str\n};
This gives me an error with MoveUp "Can't call method "MoveUp" on an undefined value at ..."
wdLine is supposed to be a known Unit as far as I know...

Replies are listed 'Best First'.
Re^2: Word tables, OLE, perl, and me.
by CountZero (Bishop) on Feb 02, 2009 at 23:12 UTC
    It looks as if $selection did not get set. Are you sure $selection = $table->Select returns a "selection" object on which you can call the MoveUp(wdLine,1) method?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      To get the selection you do the following:
      $table->Select; my $selection = $word->ActiveWindow->Selection;

      - John