I want MS Access to search for text in a Word document and then, when it has found the text, select all of the text following the find to be analysed further within Access. I have the code working which finds the text using Range.Find, however, how can I then identify where to start my selection from so that I can grab the remaining text for analysis?
1 Answer
A trivial undertaking. For example:
Sub Demo()
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "Text to Find"
.Replacement.Text = ""
.MatchWildcards = False
.Format = False
.Forward = True
.Wrap = wdFindStop
.Execute
End With
If .Find.Found = True Then
.End = ActiveDocument.Range.End
MsgBox .Text
End If
End With
End Sub
Given that you haven't shown us any of your code to automate Word, I haven't bothered with that side of things.
1 Comment
RJPWilliams
Decided not to follow this one up and went about this a completely different way.
Findcall on rangerng, then following that callrngis now set to the found text. You can use that to find out the end of the found text range and so the starting point for the text following the found range. Eg see learn.microsoft.com/en-us/office/vba/word/concepts/…