Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 22,467
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
 



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 11:19 AM.


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