in reply to how to replace superscript using Win32::OLE

It worked for me in Word2000. I think maybe you want to make the <sup>...</sup> to be not superscript, but your replacement text does not change the formatting. It does, however, replace the exponent with the new text.

Replies are listed 'Best First'.
Re^2: how to replace superscript using Win32::OLE
by Anonymous Monk on Mar 09, 2005 at 02:12 UTC

    I want to replace only the superscript numbers alone, but for me all the numbers are changing.

      This seems to work:
      use Win32::OLE::Const 'Microsoft Word'; use Win32::OLE::Const 'Microsoft Office'; 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}; $rng->find->clearformatting; $rng->find->replacement->clearformatting; $rng->find->font->{Superscript}= msoTrue; $rng->find->execute({findtext=>"[0-9]", wrap=>wdFindContinue, replacewith=>"<sup>^&</sup>", matchwildcards=>'True', # matchallwordforms => msoFalse, replace=>wdReplaceAll});