rootstock -
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Word';
$Win32::OLE::Warn = 2; # Throw Errors, I'll catch them
my $Word = Win32::OLE->GetActiveObject('Word.Application')
|| Win32::OLE->new( 'Word.Application', 'Quit' );
- Ok you have opened the word application, but you have not opened a document.
When you open word normally word will open a blank document assuming you
want to work on something new. When you do this through OLE word will not open the
document for you.
foreach $rate ( $Word->ActiveDocument->Selection->{Text} ) {
if ( $rate =~ /2M/ ) {
print $rate;
}
}
- AFAIK word will not auto incrament the line of text for you as you want here. You will
either have to first make a text selection, then perform your test, then select the next
line of text through a process of offsets. ie text = first 10 Char, then text = 11 to 20 char.
** OR better yet use words own Find function to do the work for you.
check out.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/modcore/html/deovrthefindreplacementobjects.asp
and
http://aspn.activestate.com/ASPN/Mail/Message/perl-win32-users/1536977
or
http://www.suite101.com/article.cfm/perl/89607
Your BEST tool for starting out is words own macros. Decide on what you want to automate, then turn
on words macro and walk through it. You will then have a script in VBA that will perform what you
want. Then just translate it to perl. You can get help with the translation from a script VBA2Perl written
by Matthew Musgrove. It is a beginning script, but it may give you some idea on how to do the translation
Why translate from VBA to perl? VBA is not as powerful at manipulating text and perl can interface with
more applications then VBA. Try running the VBA against a directory of files, or import/export data between
non-office apps and word or excel.
To the monks: sorry for the links not linked, I can't find were to do that. This really should be automated ;)
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.