How to reverse only words into sentense by StrReverse function?

A

avkokin

Hello.
I need to turn over all words in selected text by StrReverse function.
But these words should be in right order (like in sentense). Reversing
should be only for words, not for all string. For example, I do that:
Sub reverse()
Dim strStroka As String
Dim strRev As String
strStroka = Selection.Text
strRev = StrReverse(strStroka)
Selection.Text = Replace(strStroka, strStroka, strRev)
End Sub
This code is reversed all string. Thus the order of words into
sentense is broke. I try it otherwise, but I stop by using of cycle:
Sub reverse2()
Dim myArr() As String
Dim i As Integer
Dim sStr As String
Dim strRev As String
sStr = Selection.Text
myArr = Split(sStr)
For i = 0 To myArr(sStr) 'this is error
strRev = StrReverse(sStr)
Selection.Text = Replace(sStr, sStr, strRev)
Next i
End Sub
Help me, please.
Thank you very much.
 
A

avkokin

Hello.
I need to turn over all words in selected text by StrReverse function.
But these words should be in right order (like in sentense). Reversing
should be only for words, not for all string. For example, I do that:
Sub reverse()
Dim strStroka As String
Dim strRev As String
strStroka = Selection.Text
strRev = StrReverse(strStroka)
Selection.Text = Replace(strStroka, strStroka, strRev)
End Sub
This code is reversed all string. Thus the order of words into
sentense is broke. I try it otherwise, but I stop by using of cycle:
Sub reverse2()
Dim myArr() As String
Dim i As Integer
Dim sStr As String
Dim strRev As String
sStr = Selection.Text
myArr = Split(sStr)
For i = 0 To myArr(sStr) 'this is error
strRev = StrReverse(sStr)
Selection.Text = Replace(sStr, sStr, strRev)
Next i
End Sub
Help me, please.
Thank you very much.

That is own solution (I get help):
Sub reverse2()
Dim myArr() As String
Dim i As Integer
Dim sStr As String
Dim strRev As String
sStr = Selection.Text
myArr = Split(sStr) '
For i = 0 To UBound(myArr) '
strRev = strRev & StrReverse(myArr(i)) & " "
Next i
Selection.Text = Trim(strRev)
End Sub

Thank you.
 
H

Helmut Weber

Hi Anton,
For i = 0 To myArr(sStr) 'this is error

for i = 0 to Ubound(Myarr)

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top