View Single Post
 
Old 03-01-2023, 02:09 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,142
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can record a macro that will do that. e.g.
Code:
Sub Macro1()
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "***"
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
End Sub
It might make more sense to replace your asterisks with content controls e.g.
Code:
Sub Macro2()
Dim oRng As Range
Dim oCC As ContentControl
Dim i As Integer: i = 0
    Set oRng = ActiveDocument.Range
    With oRng.Find
        .Wrap = wdFindContinue
        Do While .Execute("***")
            i = i + 1
            oRng.Text = ""
            Set oCC = oRng.ContentControls.Add(wdContentControlRichText)
            oCC.Title = "Text" & i
            oCC.Tag = oCC.Title
            oCC.LockContentControl = True
            oRng.End = oRng.End + 1
            oRng.Collapse 0
        Loop
    End With
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote