Skip to content

Instantly share code, notes, and snippets.

@DaneWeber
Created November 26, 2013 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaneWeber/7662570 to your computer and use it in GitHub Desktop.
Save DaneWeber/7662570 to your computer and use it in GitHub Desktop.
Find All Instances of the match value. You can see the results inserted into the "Immediate" debug area. Press Ctrl+G if you don't see it. See this page if you don't know how to install a macro: http://www.gmayor.com/installing_macro.htm
Option Explicit
Sub FindAllInstances()
Dim MyAR() As String
Dim i As Long
Dim match As String
match = "has"
i = 0
Selection.HomeKey Unit:=wdStory
Selection.Find.Text = match
Do While Selection.Find.Execute = True
ReDim Preserve MyAR(i)
MyAR(i) = Selection.Information(wdActiveEndPageNumber)
i = i + 1
Loop
If i = 0 Then
MsgBox "No Matches Found"
Exit Sub
End If
Debug.Print " "
Debug.Print "Search term: " & match
For i = LBound(MyAR) To UBound(MyAR)
Debug.Print MyAR(i)
Next i
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment