Code:
    Function CountWords(ByVal Text As String) As Long
        Dim re As New RegularExpressions.Regex("\b\w+\b")
        ' the following pattern means that we're looking for a word character (\w)
        ' repeated one or more times (the + suffix), and that occurs on a word
        ' boundary (leading and trailing \b sequences)
        ' the Execute method does the search and returns a MatchCollection object
        ' which in turn exposes the Count property,
        '  i.e. the result we're interested into
        CountWords = re.Matches(Text).Count
    End Function
I copied pasted changed the link kas provided.