My goal is to merge multiple paragraph based on predefined string (in an arrary) such as period (.) or question mark (?)
My sample sentence is as below (refer the image please):
The expected result will be something like this.
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
In the below code, I could achieve it using period (.), but for every other end string, I have separate macro. Depends on the end string, I run different macro. Is there way to put all these search string (. / ? / ;) in a single array and ask the code to run until it find either of them and exit from the loop and do the merge?
Blockquote
Sub FindDotToJoinParagraph()
Dim xRange As Range
Dim Srt As Variant
Dim Endee As Variant
Dim currentPosition As Range
Selection.HomeKey Unit:=wdLine, Extend:=wdMove
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="Srt" 'Bookmark
With Selection.Find
.Text = "." 'Here not just period alone, but others too
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine, Extend:=wdMove
ActiveDocument.Bookmarks.Add Range:=Selection.Range, Name:="Ends" 'Bookmark
ActiveDocument.Range( _
ActiveDocument.Bookmarks("Srt").Range.Start, _
ActiveDocument.Bookmarks("Ends").Range.Start) _
.Select
call MergeParaAndLineBreaks() 'An another sub-routine to merge
End Sub
////////////////////////////////// Sub MergeParaAndLineBreaks()
Dim oRng As Range
Set oRng = Selection.Range
Dim oFind As Range
Set oFind = Selection.Range
With oFind.Find
Do While .Execute(findtext:="[^13^l]{1,}", MatchWildcards:=True)
If oFind.InRange(oRng) Then
oFind.Text = ""
End If
Loop
End With
Set oFind = oRng
With oFind.Find
Do While .Execute(findtext:="[ ]{2,}", MatchWildcards:=True)
If oFind.InRange(oRng) Then
oFind.Text = Chr(32)
oFind.Collapse 0
End If
Loop
End With
lbl_Exit:
Set oRng = Nothing
Set oFind = Nothing
Exit Sub
End Sub
Blockquote
Could someone help me out, please!