I'm trying to use Perl's Win32::OLE module (via Dave Roth's excellent book) to automate a couple tasks I need to repeatedly perform on some Word documents. However, the book (and most web examples) tends to use Excel for examples, so I am not sure how to copy and paste effectively with the Tables collection object.

Here is a snippet of my code:

my $originalDoc = $MSWord->Documents->Open('C:\Perl\testDocument.doc') +; my $newDoc = $MSWord->Documents->Add; my $selection = $MSWord->Selection(); # this may be spurious my $count = int( $originalDoc->Tables()->{Count} ); my $range = $originalDoc->Tables()->Range( { Start => $originalDoc->Ta +bles(1)->{Range}->{Start}, End => $originalDoc->Ta +bles($count)->{Range}->{End} } ); $range->Copy(); $newDoc->Range()->Paste();

I'm getting a rather strange 'not enough storage to complete this action' error. How can I properly copy a range of tables from $originalDoc to $newDoc?

The original code used Paragraphs, not Tables, so I assume some of the bugs are artifacts from that code (or more likely my non-understanding of that code).


In reply to How can I copy and paste a range of tables in Word with Win32::OLE? by romandas

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.