View Single Post
 
Old 11-22-2023, 01:26 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default Deleting specific strings of characters in specific positions

I devised (part of) a macro to delete certain strings of characters in specific positions. It works, but can someone suggest a more efficient way to obtain the same results? Thanks!
Code:
Sub DeleteCertainStrings()

Set oRng = ActiveDocument.StoryRanges(1)
 
With oRng.Find
.Text = "Nnnnnnnnnnnn/Nnnnnnnnn^p" '1: text to delete except ^p, which is the 1st para of the 1st page
.Execute
End With
If oRng.Find.Found = True Then
oRng.Delete
End If

With oRng.Find '2: text to delete (including final space) except ^p, the 1st para of the 2nd page
 .Text = "Nn Nnn Nnnnn. Nnnn nn NNN Nnnnnnnnn ^p"
 .Execute
End With
If oRng.Find.Found = True Then
oRng.Delete
 End If

With oRng.Find '3: to delete everything except ^p, followed by 10 ^p's, which must remain
.Text = "Nnn nnnnnnnnnn nnnnn nn nnn nnnnn nn nnnnnnnnnn^l
nnnn nnn nnnnnnnn nn Nnnnn Nnnnnnn’n “Nnnnnnn” (G3-1v).^p"
.Execute
End With
If oRng.Find.Found = True Then
oRng.Delete
 End If
End Sub
Reply With Quote