#1
|
|||
|
|||
Converting a left to right doc to a right to left
Hello,
I received a DOC file, which was supposed to be written from right to left. Now, the words in themselves are written correctly, but the sentences as a whole are written from left to write, i.e. the last word in the sentence appears on the right, the next one to the left is the one before last word, etc. But since this is an RTL language, the first word on the right should also have been the first word of the sentence. The RTL icon is highlighted, which means that WORD sees it as an RTL document. But still the order of the words is reversed. I know that this file was not composed in MS Word but converted into it. Does anybody know how I can reverse back the order of the words in the sentence? Thanks. |
#2
|
||||
|
||||
Hi seli,
You might be able to get the result you're after via a macro like: Code:
Sub ReverseParagraphSentenceText() Dim oPara As Paragraph, Rng As Range, RngStart As Range, RngEnd As Range, i As Long For Each oPara In ActiveDocument.Paragraphs Application.ScreenUpdating = False If InStr(Trim(oPara.Range.Text), " ") > 0 Then Set Rng = oPara.Range With Rng .End = .End - 1 While .Characters.Last.Text Like "[ " & vbTab & Chr(11) & "]" .End = .End - 1 If .End = .Start Or InStr(Trim(.Text), " ") = 0 Then GoTo NextPara Wend While .Characters.First.Text Like "[ " & vbTab & Chr(11) & "]" .Start = .Start + 1 If .Start = .End Or InStr(Trim(.Text), " ") = 0 Then GoTo NextPara Wend Set RngStart = Rng.Characters.First Set RngEnd = Rng.Characters.Last RngStart.Collapse wdCollapseStart For i = UBound(Split(.Text, " ")) To 1 Step -1 RngStart.Collapse wdCollapseEnd RngEnd.Start = .Start + InStrRev(.Text, Split(.Text, " ")(i)) - 1 RngEnd.Cut RngStart.Paste .Start = RngStart.End Next .Characters.Last.Text = vbNullString End With End If Application.ScreenUpdating = True Application.ScreenRefresh NextPara: Next Set Rng = Nothing: Set RngEnd = Nothing: Set RngStart = Nothing End Sub Code:
Sub ReverseText() Dim oSent As Range, Rng As Range, RngStart As Range, RngEnd As Range, i As Long For Each oSent In ActiveDocument.Sentences Application.ScreenUpdating = False If InStr(Trim(oSent.Text), " ") > 0 Then Set Rng = oSent With Rng .End = .End - 1 While .Characters.Last.Text Like "[. " & vbTab & vbCr & Chr(11) & "]" .End = .End - 1 If .End = .Start Or InStr(Trim(.Text), " ") = 0 Then GoTo NextPara Wend While .Characters.First.Text Like "[ " & vbTab & Chr(11) & "]" .Start = .Start + 1 If .Start = .End Or InStr(Trim(.Text), " ") = 0 Then GoTo NextPara Wend Set RngStart = Rng.Characters.First Set RngEnd = Rng.Characters.Last RngStart.Collapse wdCollapseStart For i = UBound(Split(.Text, " ")) To 1 Step -1 RngStart.Collapse wdCollapseEnd RngEnd.Start = .Start + InStrRev(.Text, Split(.Text, " ")(i)) - 1 RngEnd.Cut RngStart.Paste .Start = RngStart.End Next End With End If Application.ScreenUpdating = True Application.ScreenRefresh NextPara: Next Set Rng = Nothing: Set RngEnd = Nothing: Set RngStart = Nothing End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 04-23-2012 at 06:10 PM. Reason: Added code for sentence-level processing |
#3
|
|||
|
|||
Thanks Macropod
I hoped there would be a more simple solution. Macros are a bit out of my league, but I'll try using the guide to install and see how it goes.
Thanks again for your effort. Seli |
#4
|
||||
|
||||
Oh, there is a simpler solution, but you probabaly won't like that:
cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, cut-paste, etc.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
TOC is right to left for unkown reason | Guy Roth | Word | 12 | 12-05-2012 08:44 AM |
Left and right alignment on same line | leahca | Word | 6 | 10-26-2011 06:36 PM |
All text shift to the left??? | ewallet | Word | 1 | 06-21-2011 08:41 AM |
How to return to where you left off? Shift+F5 not working. | WaltR | Word | 2 | 12-24-2010 11:33 AM |
Writing from right to left | AmitD | Word | 0 | 11-01-2008 06:54 AM |