Dear Gurus & Gurettes.

My apologies in advance for asking such a foolish and ignorant question,
however, I've searched Activestate, CPAN, PerlMonks, etc. and, although it's
probably there I cannot find the help I need. Ergo, I must turn to you for
guidance.

My issue is this ... I need to retrieve a word document, append information
(a table) to the word document and save it ... simple.

The problem I'm having is that the table I'm creating is overwriting
everything on the source document ... not appending the table to whatever is
already on the source document which is what I'm looking for ...

The goal is to retrieve a document, append a new table to it at various
times, then re-save ...

Here's what I have so far ...

sub AppendWordDocument {

use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

my $ObjectClass = "Word.Application";
my $File  = "c:\\doclocation\\testmerge.doc";
my $File2  = "c:\\doclocation\\testmerge2.doc";

my $Word = Win32::OLE->GetActiveObject($ObjectClass) ||
Win32::OLE->new($ObjectClass, 'Quit');

$Word->{'Visible'} = 1;

$Word->Documents->Add || die("Unable to create document ",
Win32::OLE->LastError());

my $MyRange = $Word->ActiveDocument->Content;
my $mytxt = "Comment Text";

$Word->ActiveDocument->Tables->Add({
   Range => $MyRange,
   NumRows => 1,
   NumColumns => 1,
});

$Word->Selection->TypeText ({Text => $mytxt});
$Word->Selection->MoveRight({Count => 1});
$Word->Selection->TypeText ({Text => "Cell Text"});

$Word->ActiveDocument->SaveAs({FileName => $File2, FileFormat =>
wdFormatDocument});

$Word->Quit();

print Win32::OLE->LastError();

#&TestMessage($MyRange);
&db_logoff;
exit;

} # END SUB AppendWordDocument

What I'm getting is the new document with the table as defined above, but
the information contained on the source is overwritten.

I'm pretty certain that this has to do with the $MyRange variable ... which
appears to be collecting existing content from the source document ... is
this correct? If so, should I copy/paste this into the new document? I'm at
a loss (obviously) and could use whatever advice/guidance/assistance your
humanity will allow.

Thanks in advance.

FH

Frank Howard
InfluenceMedia
615-467-2880
[EMAIL PROTECTED]

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to