View Single Post
 
Old 03-06-2023, 09:27 PM
BrianHoard BrianHoard is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

I'm using Office 2019, but please see if this works for you. I recorded a Macro to do as you mentioned, then modified that code to get this. I added an Undo record so the entire script can be undone in one go, and used the document range instead of selection.
I now see that Graham posted an answer already. I'm still learning this, so you're likely better off going with his solution.


Code:
Sub smallCaps2Lowercase()
  Dim bhhUndo As UndoRecord
  Dim scriptName As String
  Dim rng_doc As Range
    
  scriptName = "smallCaps2Lowercase"
  Set rng_doc = ActiveDocument.Range
  Application.ScreenUpdating = False
  
  ' Begin undo record
  Set bhhUndo = Application.UndoRecord
  bhhUndo.StartCustomRecord (scriptName)
  
    ' Find/replace all text from smallCaps to lowercase.
  rng_doc.Find.ClearFormatting
  
  With rng_doc.Find.Font
    .SmallCaps = True
    .AllCaps = False
  End With
  
  rng_doc.Find.Replacement.ClearFormatting
  With rng_doc.Find.Replacement.Font
    .SmallCaps = False
    .AllCaps = False
  End With
  
  With rng_doc.Find
    .Text = "*"
    .Replacement.Text = LCase("")
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = True
  End With
  
  rng_doc.Find.Execute Replace:=wdReplaceAll

  Application.ScreenUpdating = True
  bhhUndo.EndCustomRecord ' End undo

End Sub
Reply With Quote