The code is meant to search through the current open Word document and select all instances of currently selected text. For example, I select "Casted" run the macro, and anywhere the text "Casted" appears, all of the instances are simultaneously selected [like ctr-clicking for multiple selections]
Sub SelectAllText()
Dim searchText As String
searchText = Selection.Text
If searchText <> "" Then
Dim foundRange As Range
Set foundRange = ActiveDocument.Range
With foundRange.Find
.ClearFormatting
.Text = searchText
.Forward = True
.Wrap = wdFindStop
.MatchWholeWord = True
.MatchCase = False
.Execute
Do While .found
foundRange.Select 'what i needed to work
foundRange.HighlightColorIndex = wdYellow 'This is just to highlight, not what i needed
.Execute
Loop
End With
End If
End Sub
So the code does selects the texts, but when the next instance is being selected, the previous one gets deselected. So at the end of the day only the last instance is the document remains selected, meanwhile i want everything to remain selected.