How to Reverse the Order of Specific Consecutive Words

R

RandomPattern

Hi I type many documents in English with that includes sporadic Hebrew words
throughout. Because I cannot touch type Hebrew, I transliterate them with
English characters, and I keep an excel spreadsheet with all my
transliterations and their corresponding Hebrew words in the other.

It was relatively simple to write some VBA to find the transliterations in
my document, and replace them with the corresponding Hebrew words from Excel.
The issue is phrases. Since Hebrew is written from right to left, my code
causes all the Hebrew phrases to be written in reverse. The only way I could
fix this, is to include the whole phrase in my table with the corresponding
Hebrew phrase, which is very annoying.

There has to be away to either, have my code find any consecutive
transliterations and reverse their order before converting them to Hebrew, or
to first convert them to Hebrew and then reverse the order of any consecutive
Hebrew words.

I don't know how to code that.

Any suggestions?
 
R

RandomPattern

No Larry, I don't need to reverse the letters in the word, I need to reverse
the words in a phrase. For example, a phrase like "man up what's" would need
to be switched to "what's up man"
 
G

Greg Maxey

Something like this;
Sub ReverseWords()
Dim oRng As Word.Range
Dim wordArray() As String
Dim tempStr As String
Dim i As Long
Set oRng = ActiveDocument.Range
oRng.End = oRng.End - 1
wordArray = Split(oRng.Text)
For i = UBound(wordArray) To 0 Step -1
tempStr = tempStr + Trim(wordArray(i)) & " "
Next i
ActiveDocument.Range.Text = tempStr
End Sub
 

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