Hello everyone,
I am not a pro with vba so I hope I word this correct.
I am using vba in Word 2016 to merge a document. In my legal style of the document, the combined defendants sometimes has "
as his/her spouse" at the end of the 2nd defendant's name. I insert a bookmark at the beginning of the legal style and another at the end of the style to search for the words "as his/her spouse. And, if found place it in other areas of the document. This done with additional bookmarks. Below is the vba code I tried using. Problem is that, it inserts
as his/her spouse even if it is not found between the bookmarks. What am I doing wrong?
Legal Style Example
Quote:
The Lending Institution
Plaintiff
vs.
{Style1}John doe, Jane doe as his/her spouse, Mary Jane,
Jack Spratt, ABC Company, The Home Owners Association,
Unknown tenants, Unknown Spouse.{Style2}
Defendant
|
This is the code I used
Code:
Sub SelectTextBetweenBookmarks()
Dim mark As Range
Set mark = ActiveDocument.Range
mark.Start = mark.Bookmarks("Style1").Range.End
mark.End = mark.Bookmarks("Style2").Range.Start
mark.Select
Selection.Find.ClearFormatting
With Selection.Find
.Text = "as his/her spouse"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Selection.GoTo What:=wdGoToBookmark, Name:="Spouse1"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.GoTo What:=wdGoToBookmark, Name:="Spouse2"
With ActiveDocument.Bookmarks
.DefaultSorting = wdSortByLocation
.ShowHidden = True
End With
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub
Thanks in advance for your assistance.