Thread: [Solved] remove stacking fractions
View Single Post
 
Old 10-18-2018, 10:01 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The ¼, ½, & ¾ fractions are typically single characters, not the three separate characters you'd get with fractions like 1/3, 2/3, etc. Assuming what you have is the ¼, ½, & ¾ characters, you can simply use Find/Replace to replace ¼ with 1/4, ½ with 1/2, & ¾ with 3/4. For a macro you might use to process a folder full of document containing such fractions, try:
Code:
Sub BulkFindReplace()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document, i As Long
Dim FList, RList: FList = Array("¼", "½", "¾"): RList = Array("1/4", "1/2", "3/4")
'Get the folder to process
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
'Process each document in the folder
While strFile <> ""
  If strFolder & "\" & strFile <> strDocNm Then
    Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
    'Process each word from the F/R List
    With wdDoc
      With .Range.Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .MatchWholeWord = True
        .MatchCase = True
        .Wrap = wdFindContinue
        'Process each item in the Find/Replace Lists
        'First dealing with numbers like 1?
        For i = 0 To UBound(FList)
          .Text = "([0-9])" & FList(i)
          .Replacement.Text = "\1^s" & RList(i)
          .Execute Replace:=wdReplaceAll
        Next
        'Then processing and remaining fraction charcters
        For i = 0 To UBound(FList)
          .Text = FList(i)
          .Replacement.Text = RList(i)
          .Execute Replace:=wdReplaceAll
        Next
      End With
      'Close the document
      .Close SaveChanges:=True
    End With
  End If
  'Get the next document
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
Do be aware that only single-character fractions and numbers combined with the single-character fractions, such as 1½, will be processed. A number like 1½, will now appear as 1 1/2.

For PC macro installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm
For Mac macro installation & usage instructions, see: https://wordmvp.com/Mac/InstallMacro.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote