Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-23-2012, 10:01 AM
seli seli is offline Converting a left to right doc to a right to left Windows 7 64bit Converting a left to right doc to a right to left Office 2010 64bit
Novice
Converting a left to right doc to a right to left
 
Join Date: Apr 2012
Posts: 2
seli is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 04-23-2012, 05:42 PM
macropod's Avatar
macropod macropod is offline Converting a left to right doc to a right to left Windows 7 64bit Converting a left to right doc to a right to left Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
The above macro works at the paragraph level. To reverse text at the sentence level only, use:
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
For installation/usage instructions, see: http://www.gmayor.com/installing_macro.htm
__________________
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
Reply With Quote
  #3  
Old 04-23-2012, 11:13 PM
seli seli is offline Converting a left to right doc to a right to left Windows 7 64bit Converting a left to right doc to a right to left Office 2010 64bit
Novice
Converting a left to right doc to a right to left
 
Join Date: Apr 2012
Posts: 2
seli is on a distinguished road
Thumbs up 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
Reply With Quote
  #4  
Old 04-23-2012, 11:39 PM
macropod's Avatar
macropod macropod is offline Converting a left to right doc to a right to left Windows 7 64bit Converting a left to right doc to a right to left Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a left to right doc to a right to left 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
Converting a left to right doc to a right to left 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:27 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft