Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 06-29-2022, 05:48 AM
gmaxey gmaxey is offline VBA to find and replace but ask to continue Windows 10 VBA to find and replace but ask to continue Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you use the find and replace tool to find dates and times in Excel 2013? Jules90 Excel 3 04-14-2020 07:40 PM
In Find and Replace, can Word stop after each Replace? wardw Word 1 06-08-2017 02:47 PM
VBA to find and replace but ask to continue Find what box in Find and replace limits the length of a search term Hoxton118 Word VBA 7 06-10-2014 05:05 AM
VBA to find and replace but ask to continue Bad view when using Find and Find & Replace - Word places found string on top line paulkaye Word 4 12-06-2011 11:05 PM
VBA to find and replace but ask to continue Help with find and replace or query and replace shabbaranks Excel 4 03-19-2011 08:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft