View Single Post
 
Old 05-09-2016, 07:36 AM
equalizer88 equalizer88 is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Jul 2015
Posts: 15
equalizer88 is on a distinguished road
Default

Ok, figured out problem was difference between Select and Range properties. I was missing the wdDoc.Select inside the With wdDoc loop. That is why the search was not looking in external files.

So why does the Range Object With .Range.Find not require specifying the external file? (Such as wdDoc.Range)



Code:
    While strFile <> ""
        Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, ReadOnly:=True, Visible:=False)
        With wdDoc
            Application.ScreenUpdating = False
'  **************************
 wdDoc.Select 'this was missing line 
' ***************************
     Selection.HomeKey Unit:=wdStory     ' It starts the search from the start of the document.
            'With .Range.Find 
' ****************************************
' if .Range.Find is used then no selection of WdDoc is required
'*****************************************
            With Selection.Find
              '.ClearFormatting
              .Forward = True
              .Wrap = wdFindContinue
              .Format = False
              .MatchCase = False
              .MatchWholeWord = False
              .MatchWildcards = False
             '.MatchSoundsLike = False
              .MatchAllWordForms = False
              .Text = "first"
              .Execute 'Replace:=wdReplaceAll
          'If .Found = True Then
            If Selection.Find.Found = True Then
                Print #DestFileNum, wdDoc.Name
            End If
           End With
        .Close SaveChanges:=False
        End With
        strFile = Dir()
    Wend
 ......
Reply With Quote