I long ago decided to add AutoCorrect entries for the ones that I use and turn off the AutoFormat as you type entry for fractions (so they all look the same).
One thing to watch out for when using AutoCorrect is that dates entered as D/M without the year might also get reformatted...
For a macro solution that solicits the fraction for formatting as you input it, try:
Sub EnterFraction()
'Add this macro to your Normal.dot
'Assign a keystroke like Alt-/ to this macro (Tools...Customize...Keyboard)
'Prompt user for the text to format as a fraction
fraction = InputBox("Enter fraction text (ex: 1/2, 5/32)")
'Find the position of the slash in the text
slashPosition = InStr(fraction, "/")
'Quit if no slash in the text
If slashPosition = 0 Then Exit Sub
preSlash = Left(fraction, slashPosition - 1)
postSlash = Right(fraction, Len(fraction) - slashPosition)
With Selection
.Font.Size = .Font.Size * 0.875
'Type text before the slash as superscript
.Font.Superscript = True
.TypeText preSlash
'Type the slash as normal text
.Font.Superscript = False
.TypeText "/"
'Format text after the slash
.Font.Subscript = True
.TypeText postSlash
'Continue with font back to normal
.Font.Subscript = False
End With
End Sub
or:
Sub MakeFraction()
Dim Fraction As String, Numerator As String, Denominator As String
ActiveWindow.View.ShowFieldCodes = True
With Selection
' For user input, you could use the following 2 lines to create a fraction
Fraction = InputBox("Please input the Fraction (ex: 1/2, 5/32)")
.Collapse (wdCollapseStart)
' Alternatively, to convert a selection, use the following line
'Fraction = Trim(.Text)
Numerator = Split(Fraction, "/")(0)
Denominator = Split(Fraction, "/")(1)
.Font.Size = Round(.Font.Size) / 2
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="EQ \f(" & Numerator & "," & Denominator & ")"
.MoveLeft wdCharacter, 2
.Delete
.Fields.Update
End With
ActiveWindow.View.ShowFieldCodes = False
End Sub
The first of these simply takes an input string and reformats it, whilst the second employs an EQ field to deliver a comparable result, but formatted with a horizontal line between the numerator and denominator. The latter can even do the same with text strings.
And, finally, here’s a macro with which you simply type your fraction into the document, select the fraction and run the macro - a process that can also be used for any existing fractions you might have.
Sub Fraction()
Dim RngTmp As Range, StrFrac
With Selection
StrFrac = Split(Selection.Text, "/")
Set RngTmp = .Range
With RngTmp
.Font.Size = .Font.Size * 0.875
.End = .Start + Len(StrFrac(0))
.Font.Superscript = True
.Characters.Last.Next.Font.Italic = True
.End = .End + 2 + Len(StrFrac(1))
.Start = .End - Len(StrFrac(1)) - 1
.Font.Subscript = True
End With
End With
Set RngTmp = Nothing
End Sub