20 | 09 | 2017

VisibleVisual.com | Word VB Articles

Check if Word document contains a certian string

The function below return True if a word document contains a certain string. 

Public Function WordDocContains(ByRef oDoc As Word.Document, ByVal searchFor As String) As Boolean
    Application.StatusBar = "Checking for keyword: " & searchFor
    WordDocContains = False
    Dim storyRange As Word.Range
    For Each storyRange In oDoc.StoryRanges
        With storyRange.Find
            .Text = searchFor
            WordDocContains = WordDocContains Or .Execute
        End With
        If WordDocContains Then Exit For
End Function

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles