Vanessa,
Doug Robbins and I (mostly Doug) worked on something for this a year so ago.
Say you want to replace H2O with the Hsubcript2O then in the first message
box that appears, type UP. The rest is self explanatory in the prompts.
Sub Exponents()
Dim Message, Title, Default, Characterformat As String
Starthere:
Message = "Enter Up for superscript; Down for Subscript"
Default = "Up"
Characterformat = UCase(InputBox(Message, Title, Characterformat))
Message = "Enter the search pattern" ' Set prompt.
Title = "Search Pattern" ' Set title.
Default = "H2O2" ' Set default.
GetInput:
SearchString = InputBox(Message, Title, Default)
If SearchString = "" Then
End 'quit subroutine
End If
Dim Message1, Title1, Default1, FirstScriptCharacter
Message1 = "Counting from the left, enter the number of the first
script" _
& " character" ' Set prompt."
Title1 = "First Script Character" ' Set title.
Default1 = "2" ' Set default.
GetInput1:
FirstScriptCharacter = InputBox(Message1, Title1, Default1)
Dim Message2, Title2, Default2, SecondScriptCharacter
Message2 = "Counting from the left, enter the number of the second
script character" ' Set prompt.
Title2 = "Second Script Character" ' Set title.
Default2 = "4" ' Set default.
GetInput2:
SecondScriptCharacter = InputBox(Message2, Title2, Default2)
Dim Message3, Title3, Default3, ThirdScriptCharacter
Message3 = "Counting from the left, enter the number of third script " _
& " character" ' Set prompt."
Title3 = "Third Script Character" ' Set title.
Default3 = "" ' Set default.
GetInput3:
ThirdScriptCharacter = InputBox(Message3, Title3, Default3)
Dim Message4, Title4, Default4, FourthScriptCharacter
Message4 = "Counting from the left enter the number of the fourth script
" _
& "character " ' Set prompt."
Title4 = "FourthScriptCharacter" ' Set title.
Default4 = "" ' Set default.
GetInput4:
FourthScriptCharacter = InputBox(Message4, Title4, Default4)
Dim myrange As Range
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=SearchString, MatchWildcards:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
If Characterformat = "DOWN" Then
If IsNumeric(FirstScriptCharacter) Then
myrange.Characters(FirstScriptCharacter).Font.Subscript = True
If IsNumeric(SecondScriptCharacter) Then
myrange.Characters(SecondScriptCharacter).Font.Subscript = True
If IsNumeric(ThirdScriptCharacter) Then
myrange.Characters(ThirdScriptCharacter).Font.Subscript = True
If IsNumeric(FourthScriptCharacter) Then
myrange.Characters(FourthScriptCharacter).Font.Subscript = True
ElseIf Characterformat = "UP" Then
If IsNumeric(FirstScriptCharacter) Then
myrange.Characters(FirstScriptCharacter).Font.Superscript = True
If IsNumeric(SecondScriptCharacter) Then
myrange.Characters(SecondScriptCharacter).Font.Superscript = True
If IsNumeric(ThirdScriptCharacter) Then
myrange.Characters(ThirdScriptCharacter).Font.Superscript = True
If IsNumeric(FourthScriptCharacter) Then
myrange.Characters(FourthScriptCharacter).Font.Superscript = True
Else
MsgBox "Invalid Entry. You must enter either Up or Down."
GoTo Starthere
End If
Loop
End With
End Sub