replace format (subscript)

  • Thread starter Thread starter Lamb Chop
  • Start date Start date
L

Lamb Chop

Is it possible to do the following:

I would like to change "O2" to

O<subscript> 2</subscript>

I can only change the whole word "O2" to

<subscript> O2 </subscript>

If I just replace "2", I will run into trouble because the whole document
has a lot of numbers.

I use office 2k

Thanks
 
You can do it in stages.
Replace O2 with
O &&2
(Note the space)
Replace &&2
with ^& format superscript
Replace space&&
with nothing

or by macro

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "O2"
.Replacement.Text = "O &&2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "&&2"
.Replacement.Text = "^&"
.Replacement.Font.Superscript = True
End With
Selection.Find.Execute replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " &&"
.Replacement.Text = ""
End With
Selection.Find.Execute replace:=wdReplaceAll

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Thanks, Graham

A very good trick.




Graham Mayor said:
You can do it in stages.
Replace O2 with
O &&2
(Note the space)
Replace &&2
with ^& format superscript
Replace space&&
with nothing

or by macro

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "O2"
.Replacement.Text = "O &&2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "&&2"
.Replacement.Text = "^&"
.Replacement.Font.Superscript = True
End With
Selection.Find.Execute replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = " &&"
.Replacement.Text = ""
End With
Selection.Find.Execute replace:=wdReplaceAll

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top