in reply to Re^6: Reading tables in MS Word
in thread Reading tables in MS Word

In what way does your snippet not work? If you don't tell me, I can't really help you there.

Pressing ALT+F11 in Word opens up the VBA "IDE", and then pressing CTRL+G gives you a console where you can enter VBA commands to try them out.

That could help you narrow down where your Perl code goes wrong.

Replies are listed 'Best First'.
Re^8: Reading tables in MS Word
by spiral (Novice) on Jul 16, 2025 at 21:11 UTC
    for my $table (in $tables) { my $rownum=1; while($rownum<=$table->Rows->Count){ print "calling cell1\n"; my $cell1=$table->Cell($rownum,1); print "cell1-$cell1 calling text\n"; # prints cell1-Win32::OLE=HASH(0x1c7fbc32b50) calling text my $text1=$cell1->ConvertToText(wdSeparateByTabs)->Text; #This is where it fails with the message #Win32::OLE(0.1713) error 0x80020011: "Does not support a collection" # in METHOD/PROPERTYGET "" print "after text1cell1 = $text1\n"; $rownum++;} }

      You can't make up function calls and expect them to work. Where in the (already linked) Microsoft Documentation did you find that the ->ConvertToText method exists on the Cell object?

      Following the approach I outlined above with the interactive testing window of Microsoft Word, I used the following snippet to get at the text content of an arbitrary cell:

      set T = activeDocument.Tables.Item(1) print T.Cell(2,2).Range.Text

      Translating this to Perl would be something like this:

      print $table->Cell(2,2)->Range->Text