Public Function Words(Text_String As String) As Integer

'       This function will count the number of words in a string
'       if the string is blank (or null) 0 is returned
       
WordString = Text_String
Dim WordArray() As String
Dim WordCounter As Long
If WordString <> "" Then

    '       First eliminate any duplicate spaces
    
    With CreateObject("VBScript.RegExp")
        .Pattern = "\s+"
        .Global = True
        WordString = .Replace(WordString, " ")
    End With

    Words = 1
    Dim String_Length As Integer
    Dim Current_Character As Integer
    Stripped = "N"

    '       Now remove leading spaces

    Do While Stripped = "N"
        String_Length = Len(WordString)
        If Left(WordString, 1) = " " Then
            WordString = Right(WordString, (String_Length - 1))
        Else
            Stripped = "Y"
        End If
    Loop

    '       Now count the words
    
    WordArray = VBA.Split(WordString, " ")
    Words = UBound(WordArray) + 1
Else
    Words = 0
End If
End Function