title: Automatisation of macros
body: <p>I have a Word document and I want to do following with it:</p>
  
  <ol>
  <li>Select some part of it when I open a Word doc (let´s say from page 40 to 45).</li>
  <li>Reverse text in selected area.</li>
  <li>Get text reversed again as it was before opening, when I close document.</li>
  </ol>
  
  <p>I have this code, that reverses the text:</p>
  
  <pre><code>Sub ReverseSelectedWords()
      Dim i As Integer
      Dim oWords As Words
      Dim oWord As Range
  
      Set oWords = Selection.Range.Words
  
      For i = 1 To oWords.Count Step 1
          Set oWord = oWords(i)   
  
          Do While oWord.Characters.Last.Text = " "
              Call oWord.MoveEnd(WdUnits.wdCharacter, -1)
          Loop
  
          Debug.Print "'" &amp; oWord.Text &amp; "'"
          oWord.Text = StrReverse(oWord.Text)
      Next i
  End Sub
  </code></pre>