add nice fractions

When you type 1/2 it AutoCorrects to ½ which looks a lot nicer, but few fractions AutoCorrect and it is not possible to add more to the AutoCorrect list. You can use the Fraction button in Insert > Equation:

but it’s in Cambria Math (sic) font which has to be changed using this macro so I use a macro which turns anything with a slash into a nice fraction. If you have the macro on the Quick Access Toolbar you just need to select the fraction then click the button.

The slash is replaced with a symbol slanting at a better angle. See my macro here to find the Unicode value of any character.

The code is:

Sub MakeFraction()
‘make fraction
Dim fractionbit As Range
Dim iSlashPlace As Integer
With Selection
iSlashPlace = InStr(.Text, “/”)
Set fractionbit = ActiveDocument.Range _
(Start:=.Start, End:=.Start + iSlashPlace – 1)
fractionbit.Font.Superscript = True
fractionbit.Font.Position = -1
Selection.Font.Size = 14
Set fractionbit = ActiveDocument.Range _
(Start:=.Start + iSlashPlace, End:=.End)
fractionbit.Font.Subscript = True
fractionbit.Font.Position = 1
‘fractionbit.Font.Spacing = 1
Selection.Font.Size = 14
End With
‘replace slash
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Spacing = 1
With Selection.Find
.Text = “/”
.Replacement.Text = ChrW(8260)
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
End With
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: