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

I typed data in word file (test.docm) and tried running following code. It works by searching data in current word file from where the VBA is running. If I copied this exact search to my code with files it doesn't work if I delete data from the test.docm file. I'm thinking that Selection in my code on first post is searching the test.docm data and not looking in the text files?? However, Range is searching the text files in folder.



Code:
Sub SearchFN()
    Dim iCount As Integer

    'Always start at the top of the document
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
        .ClearFormatting
        .Text = "1"
        '.Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = True
        .Execute
    End With
    
        If Selection.Find.Found Then
            MsgBox "Found"
        End If
    
End Sub
Reply With Quote