How would I modify this code to check first to see that there is indeed
Phrases(0), Phrases(1), and Phrases(2) so I won't get an error if strSentence
does not have 2 tabs in the sentence?
thanks,
ck
Phrases = Split(strSentence, vbTab)
str1 = Phrases(0) ' so you can see what they are
str2 = Phrases(1)
str3 = Phrases(2)
Greg Maxey - 28 Mar 2006 03:15 GMT
I suppose you could look for and count them first:
Sub Test()
Dim Phrases As Variant
Dim strSentence As String
Dim str1 As String, str2 As String, str3 As String
Dim i As Long
strSentence = Selection.Text
With Selection.Find
.Text = vbTab
While .Execute
If .Found Then i = i + 1
Wend
End With
If i = 2 Then
Phrases = Split(strSentence, vbTab)
str1 = Phrases(0) ' so you can see what they are
str2 = Phrases(1)
str3 = Phrases(2)
End If
End Sub

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> How would I modify this code to check first to see that there is
> indeed Phrases(0), Phrases(1), and Phrases(2) so I won't get an error
[quoted text clipped - 6 lines]
> str2 = Phrases(1)
> str3 = Phrases(2)
Jezebel - 28 Mar 2006 04:25 GMT
Phrases = Split(strSentence, vbTab)
For i = 0 to ubound(Phrases)
Select case i
Case 0
str1 = Phrases(0)
Case 1
str1 = Phrases(1)
Case 2
str1 = Phrases(2)
case else
end select
Next
> How would I modify this code to check first to see that there is indeed
> Phrases(0), Phrases(1), and Phrases(2) so I won't get an error if
[quoted text clipped - 7 lines]
> str2 = Phrases(1)
> str3 = Phrases(2)