Public Function Word(InString As String, Pick As Integer) As String

'       This function will return the nth word of a string (as speified by the Pick value)
'       if the string is blank (or empty) nothing is returned
'       If you ask for a word that is higher than the string length; nothing is returned
 
Dim WordArray() As String
Dim WordCounter As Long
wordstring = InString

'       First eliminate any duplicate spaces

With CreateObject("VBScript.RegExp")
    .Pattern = "\s+"
    .Global = True
    wordstring = .Replace(wordstring, " ")
End With
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

'       Build array of words

WordArray = VBA.Split(wordstring, " ")

'       Get length of array (number of words)

WordCounter = UBound(WordArray)

    If WordCounter = 0 Then
        If WordArray(0) <> "" Then
            Word = WordArray(0)
            Exit Function
        End If
    End If

'       Locate our word (if appropriate)
 
If WordCounter < 1 Or (Pick - 1) > WordCounter Or Pick < 0 Then
    Word = ""
Else
    Word = WordArray(Pick - 1)
End If
End Function