title: word vba selection.endkey extend
body: <p>I'm having trouble with Selection.EndKey Extend:=wdExtend.</p>
  
  <p>Windows 7 64bit, Office 2013 with the following References checked in my Project References dialog: </p>
  
  <p>•   Visual basic For applications 
  •   Microsoft Word 15.0 Object Library
  •   OLE Automation
  •   Normal
   •  Microsoft Office 15.0 Object Library</p>
  
  <p>I open a Word document that consist of one sentence paragraphs (no periods at the ends). My desire is to select each paragraph and replace it with an entry from a predefined table.</p>
  
  <p>Here is the original code:</p>
  
  <pre><code>For i = intFirstItemNo To intLastItemNo
    Selection.EndKey Extend:=wdExtend
    Selection.TypeText Text:=arlAdItem01(i)
    Selection.MoveRight unit:=wdCharacter, Count:=1
  Next i
  </code></pre>
  
  <p>I then discovered that occasionally there will be a paragraph that is longer than the page width and wraps around to the next physical line. At this point the code above truncates the paragraph at the end of the line (unit:=wdLine is the default).</p>
  
  <p>After much experimentation I've discovered that only the enumerations 5=wdLine &amp; 6=wdStory work. 1 through 4 (1=wdCharacter, 2=wdWord, 3=wdSentence, 4=wdParagraph) produce the old "Run time error '4120'" message. </p>
  
  <p>This is the line I want to use:</p>
  
  <pre><code>Selection.EndKey Unit:=wdParagraph, Extend:=wdExtend
  </code></pre>
  
  <p>My question is, does anyone know how to make the code work the way it's described to work in the Selection.EndKey Method (Word) entry of the Office Dev Center?</p>