Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-10-2016, 02:09 PM
macropod's Avatar
macropod macropod is offline Shuffling a sentence Windows 7 64bit Shuffling a sentence 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

For that, you could use a macro like:


Code:
Sub Demo()
Randomize Timer
Dim StrTxt As String, StrTmp As String, StrOut As String
Dim i As Long, j As Long
With Selection.Range
  .Start = .Sentences.First.Start
  .End = .Sentences.First.End
  While .Characters.Last Like "[.!:;?" & vbCr & vbTab & vbLf & "]"
    .End = .End - 1
  Wend
  StrTxt = " " & Trim(.Text) & " "
  While Len(Trim(StrTxt)) > 1
    i = UBound(Split(StrTxt, " ")) + 1
    j = Int(Rnd * i)
    If j > 0 Then
      StrTmp = Split(StrTxt, " ")(j) & " "
      StrOut = Trim(StrOut & " " & StrTmp)
      StrTxt = Replace(StrTxt, " " & StrTmp, " ", 1, 1)
    End If
  Wend
  .Text = StrOut
End With
End Sub
Simply click anywhere in the sentence and run the macro. Do note, though, that a VBA sentence is not the same as a grammatical sentence - periods used in abbreviations, for example, get interpreted by VBA as sentence ends.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 05-10-2016, 02:25 PM
macdadi112 macdadi112 is offline Shuffling a sentence Windows 7 64bit Shuffling a sentence Office 2010 64bit
Novice
Shuffling a sentence
 
Join Date: May 2016
Posts: 6
macdadi112 is on a distinguished road
Default

Thanks the above works..

So what if I wanted it to run in every sentence in the file. Something like a for loop..
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shuffling a sentence End of sentence puncuation. nrsmd Word 2 07-04-2015 10:33 PM
Shuffling a sentence Delete does not bring second sentence closer to first sentence Andoheb Word 29 07-03-2014 01:48 PM
Shuffling a sentence First word of sentence IF and then awolf Word VBA 7 03-16-2014 02:40 PM
Space Between Each Sentence dazwm Word 2 10-17-2012 04:19 AM
Shuffling a sentence skip to next sentence? moreenz Word 3 08-16-2012 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:55 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