0

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?

5
  • 3
    Please show us your code - otherwise it is hard to help you. Commented Jun 25 at 12:06
  • What versions of Access and Word are you using? Commented Jun 25 at 13:27
  • See the documentation, especially the last part before “See Also”: learn.microsoft.com/en-us/office/vba/api/word.find Commented Jun 25 at 13:39
  • This question is similar to: How can I avoid using Select in Excel VBA?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jun 25 at 15:33
  • If you successfully execute a Find call on range rng, then following that call rng is 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/… Commented Jun 25 at 17:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Decided not to follow this one up and went about this a completely different way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.