Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Win32::OLE formattings

by maa (Pilgrim)
on Mar 09, 2005 at 07:56 UTC ( [id://437823]=note: print w/replies, xml ) Need Help??


in reply to Win32::OLE formattings

Hi, Anonymous Monk

this is just a hint, but it would help you receive answers if you explicitly stated that this is MS Word you're talking about, rather than hoping someone recognises the code or spots that wdFindContinue is a Microsoft Word constant.

As a start, can you show us the code you use to assign $rng, please?

--
Mark

Replies are listed 'Best First'.
Re^2: Win32::OLE formattings
by Anonymous Monk on Mar 09, 2005 at 08:29 UTC
    use strict; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Constant 'True' => 1; use Constant 'False' => 0; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); my $mydoc = $word->activedocument; my $rng = $mydoc->{range};

      Your original code...

      I've tried your code in Word (as a user) and it works. For anyone reading this, ^& is whatever Find just found/matched against.

      Recording a macro suggests the code:

      use strict; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; use Constant 'True' => 1; use Constant 'False' => 0; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); my $mydoc = $word->activedocument; my $Selection = $word->{Selection}; $Selection->Find->ClearFormatting(); $Selection->Find->Font->{Bold} = True; $Selection->Find->Replacement->ClearFormatting(); with ($Selection->Find->Replacement->Font, Bold => True, Italic => False ); $Selection->Find->{Text} = "[0-9]{1,}"; $Selection->Find->Replacement->{Text} = "<bold>^&</bold>"; $Selection->Find->{Forward} = True; $Selection->Find->{Wrap} = wdFindContinue; $Selection->Find->{Format} = True; $Selection->Find->{MatchCase} = False; $Selection->Find->{MatchWholeWord} = False; $Selection->Find->{MatchWildcards} = True; $Selection->Find->{MatchSoundsLike} = False; $Selection->Find->{MatchAllWordForms} = False; $Selection->Find->Execute( {Replace=>wdReplaceAll} );
      I've not tested it but hopefully it'll help...

        Thanks for your effort, it works for me, but it is replacing all the numbers in the document. What i want is, i want to replace the numbers in the bold font alone.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 07:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found