using find and replace function

A

ann

I work with scientific manuscripts. If I want to find all
the references to H20 and replace them with H2(subscript)O
without having all of H20 become subscript, how do I do
that?
 
G

Greg Maxey

Ann,

Convert one of your H2O to the correct format. Select and copy the
correctly formatted form. In the Find field type H2O in the Replace field
put ^c (this is contents of the clipboard) then select Replace all.

You might consider creating a formatted AutoCorrect entry to convert H2O to
your format as you type.
 
L

Larry

Ann,

It's true that in a straight search and replace, the entire formula gets
changed to subscript. So for this a macro with a loop is needed that
stops the search at each instance, selects the 2 and performs the
formatting operation just on the 2, then continues the search until all
the changes have been made. If you don't know how to create a macro and
assign a keystroke to it, go to this page:

http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm

Larry

Application.ScreenUpdating = False
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "<H2O>"
.Replacement.Text = ""
.Forward = True
.MatchWildcards = True
.Wrap = wdFindContinue

Do While .Execute
Selection.Characters(2).Select
Selection.Font.Subscript = True
Selection.Collapse wdCollapseEnd
Loop
End With

' clear find parameters
With Selection.Find
.Text = ""
.Replacement.Text = ""
.MatchWildCards = False
End With
 
L

Larry

Both of Greg's suggestions would also be good.

The reason why the whole word gets subscripted is that subscripting is
just like italics or underlining: it affects the entire word in which
the change occurs, unless a character is selected, in which case it just
affects that character.

Larry
 

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