No such thing as a small change | |
PerlMonks |
Re: Win32::OLE word questionsby Zero_Flop (Pilgrim) |
on May 13, 2003 at 07:07 UTC ( [id://257657]=note: print w/replies, xml ) | Need Help?? |
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 ;)
In Section
Seekers of Perl Wisdom
|
|