![]() |
#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 |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |
![]() |
WaltR | Word | 2 | 12-24-2010 11:33 AM |
Writing from right to left | AmitD | Word | 0 | 11-01-2008 06:54 AM |