Home > Back-end >  Jump to found text in document
Jump to found text in document

Time:11-20

I am programming a loop which searches for highlighted text in a document. If a text is found it should be shown in the Word window similar to the non-vba search function that you have in word. How can I achieve this?

Here is the code that I use to find the highlighted text, and it works well. But I don't now how to show the found instances in the word document.

With ActiveDocument.Range
    .Find.Highlight = True
    Do While .Find.Execute
    ' Jump to found text and prompt user to take action.
        
    Loop
End With

PS: Once an occurrence is found, I want to prompt the user via to take action on this part of the text. The context is important for the user to decide, therefore he has to see the text. I'm clear on the prompting part, but I cannot figure out how to show the text to the user.

CodePudding user response:

You need to use the .Select method. I'd recommend doing this on a .Duplicate of the current found range. e.g. Inside your do loop use '.Duplicate.Select' (NOT .Find.Duplicate.Select)

  • Related