Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Run the word macro by using Win32::OLE

by gopalr (Priest)
on Jan 21, 2005 at 09:13 UTC ( [id://423912]=perlquestion: print w/replies, xml ) Need Help??

gopalr has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Pls. guide me that how to run the MS-Word Macro by using Win32::OLE.

I get word object and find the pattern and replace it.

use OLE; use Win32::OLE::Const 'Microsoft Word'; my $const=Win32::OLE::Const->Load("Microsoft Word 9.0 Object Library") +; $word=GetObject OLE("Word.Application"); $word->Selection->HomeKey({unit=>$const->{'wdStory'}}); $word->Selection->Find->{'Text'}='google.com'; $word->Selection->Find->Replacement->{'Text'}='<web>google.com</web>'; $word->Selection->Find->Execute({Replace=>$const->{'wdReplaceAll'}});

I have a macro name called 'Macro1'. How to run this macro by using OLE.

Thanks in Advance

Gopal.R

Replies are listed 'Best First'.
Re: Run the word macro by using Win32::OLE
by wfsp (Abbot) on Jan 21, 2005 at 09:55 UTC
    try something like
    $word->run('Macro1', 'arg1');

    Updated: Too many ->
Re: Run the word macro by using Win32::OLE
by guha (Priest) on Jan 21, 2005 at 16:51 UTC

    I don't really understand the connection between your example code and the question for running a macro. However the second part of your example should be written like:

    my $range = $word->ActiveDocument->Content; $range->Find->Execute( { FindText => 'google.com', ReplaceWith => '<web>google.com</web>', Replace => $const->{'wdReplaceAll'}, } );

    This code is however untested.

    HTH

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found