replace format (subscript)

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

Lamb Chop

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top