++Thank you that did it. The working code is below, with a couple of mods to put a page break between files and put the file name in a heading at the start.

If I may be permitted a small rant: What kind of twisted mind came up with this Office object model? It is the Rube Goldberg Device of object models. Six steps to insert a heading. REALLY? It took me forever to figure out that you make a selection in the document, but then the selection belongs to to system, not that document. Geez.

#!/usr/bin/perl -w use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $word = Win32::OLE->new('Word.Application') or die "Failure - word. + \n"; $word->{'Visible'} = 1; my $outputdoc = $word->Documents->Add; my @inputdocs = qw( foo.doc bar.doc); foreach my $f (@inputdocs) { my $ip = $outputdoc->Range({Start=>$outputdoc->Content->End -1,End +=>$outputdoc->Content->End -1}); $ip->Select(); my $selection = $word->Selection; $selection->TypeText($f); $selection->{'Style'} = "Heading 2"; $selection->TypeParagraph; my $inputdoc = $word->Documents->Open({FileName => "c:\\temp\\work +\\$f"}); my $inputparagraphs = $inputdoc->Paragraphs; my $nparagraphs = $inputdoc->Paragraphs->Count; for my $i (1..$nparagraphs) { $inputdoc->Paragraphs($i)->Range->Copy; my $outrange = $outputdoc->Range({Start=>$outputdoc->Content-> +End -1,End=>$outputdoc->Content->End -1}); $outrange->Paste; } $inputdoc->close; my $outputend = $outputdoc->Range({Start=>$outputdoc->Content->End + -1,End=>$outputdoc->Content->End -1}); $outputend->InsertBreak(); } $outputdoc->SaveAs({FileName => 'c:\\temp\\work\\combined.doc'});

In reply to Re^2: Win32 OLE Word combining docs by cormanaz
in thread Win32 OLE Word combining docs by cormanaz

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.