noHandlebars
Technical User
How can you select a specific section of text, delete that section, and then insert a new section in its place using a macro.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Dim r As Range
Set r = ActiveDocument.Range
With r.Find
.Text = "quick brown fox"
.Replacement.Text = "yellow tall giraffe"
.Execute Replace:=wdReplaceAll
End With
Define "specific section of text". Specific how? By format? By location? By actual words?
[blue] Dim TextStart As Long
With ActiveDocument.Content
.Find.Execute FindText:="Section C.1"
TextStart = .Start
.Collapse wdCollapseEnd
.Find.Execute FindText:="Section C.2"
.Collapse wdCollapseStart
.Start = TextStart
.Delete
.InsertAfter "Something else"
.InsertParagraphAfter
End With
[/blue]
[blue] Dim TextStart As Long
With ActiveDocument.Content
.Find.Execute FindText:="Section C.1"
TextStart = .Start
.Collapse wdCollapseEnd
.Find.Execute FindText:="Section C.2"
.Collapse wdCollapseStart
.Start = TextStart
.Delete
[red].InsertBreak wdPageBreak[/red]
.InsertAfter "Something on a new page"
.InsertParagraphAfter
[red].Collapse wdCollapseEnd
.InsertBreak wdPageBreak[/red]
End With[/blue]