Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Win32::OLE word questions

by Zero_Flop (Pilgrim)
on May 13, 2003 at 07:07 UTC ( [id://257657]=note: print w/replies, xml ) Need Help??


in reply to Win32::OLE word questions

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 ;)

Replies are listed 'Best First'.
Re: Re: Win32::OLE word questions
by rootstock (Novice) on May 13, 2003 at 11:29 UTC
    thanks for responding.
    use Win32::OLE; # Object Linking and Embed
    use Win32::OLE::Const 'Microsoft Word'; # Defines constants word k
    my $Word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit');
    $a= $Word->Selection->Tables(1)->Cell(2,2)->Range->{Text};
    print $a;
    above codes worked
    so i thought
    $a= $Word->Selection->wdline(1)->Range->{Text};
    could work as well, but seemed the wdline(1) is a undefined value, i have been checking perl\html\OLE-Browser about the ole value, but have not work out the problems yet.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://257657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-19 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found