View Single Post
 
Old 06-29-2022, 05:48 AM
gmaxey gmaxey is offline Windows 10 Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Not very elegant, but seems to work:


Code:
Sub FindNum()
Dim oRng As Range
  Set oRng = ActiveDocument.Range
  With oRng.Find
    .ClearFormatting
    .Font.Superscript = False 'Don't find if already superscripted
    .Text = "[0-9]{1,} "
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchWildcards = True
    Do While .Execute
      oRng.Select
      Select Case MsgBox("Do you want the numbers found in the current paragraph to be subscripted?", vbYesNoCancel)
        Case vbYes
          SubscriptPara oRng.Paragraphs(1).Range
         Case vbNo
          oRng.End = oRng.Paragraphs(1).Range.End
        Case Else: Exit Sub
      End Select
      oRng.Collapse wdCollapseEnd
    Loop
  End With
lbl_Exit:
  Exit Sub
End Sub
Sub SubscriptPara(oRng As Range)
Dim oRngPar As Range
  Set oRngPar = oRng.Duplicate
  With oRng.Find
    .ClearFormatting
    .Font.Superscript = False 'Don't find if already superscripted
    .Text = "[0-9]{1,} "
    .MatchWildcards = True
     Do While .Execute
      If oRng.InRange(oRngPar) Then
        With oRng.Font
          .Bold = True
          .Color = vbBlack
          .Superscript = True
          .Size = 10
        End With
      Else
        Exit Do
      End If
      oRng.Collapse wdCollapseEnd
    Loop
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/

Last edited by gmaxey; 06-29-2022 at 12:20 PM. Reason: Correct code to OP specs
Reply With Quote