Hello there,
I am a bit new to Perl and set out to write my first Perl code using the Win32::OLE. I RTFM and went through the forums here. Seeing as I want to get off on the right foot to save myself pain later I noticed that code that I found lying on the floor of the Internet worked but some other code I found here (
http://perlmonks.thepen.com/198045.html) that resembled the MSDN way (
within this MSDN link) did not. The method in question is the "typetext" way of inserting text.
Here is my code:
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft word';
my $word = Win32::OLE->new('word.Application', '');
$word->{'Visible'} = 1;
my $wordtarget = $word->Documents->add()
|| die("Unable to open document ", Win32::OLE->LastError());
my $range = $wordtarget->{Content};
$range->InsertAfter("InsertAfter method");
$wordtarget->TypeText("typetext method");
$range->TypeText("typetext method");
The resulting word document looks like this:
Insert After method
All other text is missing. The "typetext" way does not
work with my code (I did try to "selection() my document), but does with the code I found here and to be what microsoft is pushing.
I am using ActiveState Perl 5.6 and not the CSPAN.
Can anyone show and then push me down the right fork in
this road? Many thanks.
brownsofa
janitored by ybiC: Balanced <code> tags around codeblock, PM-ified links thusly - [http://foo.bar/bat/baz.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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.