Word VBA Assistance

I have an end user who is Visually Handicapped.  He uses Word 2016 on a daily basis.  He is pretty adept with Word, but he is having a problem with the Search and Find Feature.  He needs to be able to search, and be able to go to each hit and modify as he reviews the narrative.  Once he reviews the first hit, he would use a function key to go to the next hit.   He needs this to work in all StoryRanges, including header and footer.   He does not want the find box to popup.

I have a script which has him enter his search term, then highlight all the terms in the document, in all StoryRanges.  My dilemma is moving through the document.  In essence, he should be able to enter the search term and the word should be highlighted where he can change or keep as is.  In either case, once he makes his choice, the highlight would be removed, and the a Function key should take him to the next hit until all have been handled.  

I found the script below will do a Find and Replace, but I just need a FIND ONLY.    

Public Sub FindReplaceAnywhere()

  Dim rngStory As Word.Range
  Dim pFindTxt As String
  Dim pReplaceTxt As String
  Dim lngJunk As Long
  Dim oShp As Shape

  pFindTxt = InputBox("Enter the text that you want to find." _
    , "FIND" )
  If pFindTxt = "" Then
    MsgBox "Cancelled by User"
    Exit Sub
  End If
  pReplaceTxt = InputBox( "Enter the replacement." , "REPLACE" )
  If pReplaceTxt = "" Then
    If MsgBox( "Do you just want to delete the found text?", _
     vbYesNoCancel) = vbNo Then
      GoTo TryAgain
    ElseIf vbCancel Then
      MsgBox "Cancelled by User."
      Exit Sub
    End If
  End If
  'Fix the skipped blank Header/Footer problem
  lngJunk = ActiveDocument.Sections( 1 ).Headers( 1 ).Range.StoryType
  'Iterate through all story types in the current document
  For Each rngStory In ActiveDocument.StoryRanges
    'Iterate through all linked stories
      SearchAndReplaceInStory rngStory, pFindTxt, pReplaceTxt
      On Error Resume Next
      Select Case rngStory.StoryType
      Case 6 , 7 , 8 , 9 , 10 , 11
        If rngStory.ShapeRange.Count > 0 Then
          For Each oShp In rngStory.ShapeRange
            If oShp.TextFrame.HasText Then
              SearchAndReplaceInStory oShp.TextFrame.TextRange, _
                  pFindTxt, pReplaceTxt
            End If
        End If
      Case Else
        'Do Nothing
      End Select
      On Error GoTo 0
      'Get next linked story (if any)
      Set rngStory = rngStory.NextStoryRange
    Loop Until rngStory Is Nothing

End Sub

Public Sub SearchAndReplaceInStory(ByVal rngStory As Word.Range, _
    ByVal strSearch As String , ByVal strReplace As String )

  With rngStory.Find
    .Text = strSearch
    .Replacement.Text = strReplace
    .Wrap = wdFindContinue
    .Execute Replace:=wdReplaceAll
  End With

End Sub

Any assistance is appreciated.
Jeanie Francis-HayesEnterprise Applications AdministratorAsked:
Who is Participating?
aikimarkConnect With a Mentor Commented:
I think you will need to create two slightly different macros. One prompts for the string to find (visible user interface, probably with a large font user form, and executes a find command.  The second one repeats the find command, looking further down the document.  After creating these two routines in a module, you would assign them to different keystroke combinations.
Jeanie Francis-HayesEnterprise Applications AdministratorAuthor Commented:
I have tried this.  I got the first one working great.  The second one is my issue, I am having trouble finding the highlighted Word.  I am thinking on my first find, I need to change the word to a text box, so I can find the next text box instead of a highlighed Word.  What do you think?
aikimarkConnect With a Mentor Commented:
You need to persist a variable in the General Declarations section.  This way, the variable can be accessed by both routines.  The first routine sets it based on the user input.  The second routine uses it to repeat the find.
Solutions accepted
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.