Option Explicit
Sub Test_ParseText()
Dim I As Integer, NW As Integer
Dim Cel As Range
Dim strBuffer As String, strVal As String, Words(32) As String
'
' fetch selection text
'
For Each Cel In Selection
strVal = Cel.Text
'
' parse fetched text
'
Call ParseText(strVal, " ", NW, Words)
'
' build output data
'
strBuffer = ""
For I = 1 To NW
strBuffer = strBuffer & I & " " & Words(I) & vbCrLf
Next I
'
' display results
'
MsgBox "original text = " & strVal & vbCrLf & _
"# individual words parsed = " & NW & vbCrLf & _
" individual parsed words:" & vbCrLf + strBuffer, vbInformation
Next Cel
End Sub
Sub ParseText(strBuffer As String, Delim As String, NW As Integer, Words)
'
' Function parses individual words from a text string (strBuffer) and returns
' # words found (NW) and a string array of individual words (Words)
'
Dim strItems() As String
Dim Item As Variant
'
' parse with Delim
'
strItems = Split(strBuffer, Delim)
'
' determine NW and load Words array for return
'
NW = 0
For Each Item In strItems
NW = NW + 1
Words(NW) = Item
Next
End Sub
|