none
Moving a range with Word vba RRS feed

  • Question

  • I have entered text in a table cell and collapsed the range each time to redefine it for the next text insert with rng.InsertAfter varArray(i).  This insert is multiple lines.  After inserting it, I count how many lines in the range with rng.ComputerStatistics(wdStatisticLines).  It gives me the correct count.  I want to move the range to include only the last line of the current range.  I have tried rng.MoveStart wdLine, nLines-1 and a few ofter unsuccessful attempts.  How can I accomplish this range re-definition?

    Thank you.


    • Edited by orlandp Tuesday, March 13, 2012 2:44 AM
    Tuesday, March 13, 2012 2:36 AM

Answers

  • If I recall correctly I don't think the wdLine property works with a range command. You don't get an error but it just doesn't work.  To pickup that last line you could either change the range to a selection and then move the start position or use something like this.

    Dim rng as Word.Range 'place rng in last line of table cell rng.Bookmarks("\line").Range.Text

    If you use this method, you'll have to trim off the end of cell marker.

     


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by orlandp Wednesday, March 14, 2012 1:42 AM
    Tuesday, March 13, 2012 12:52 PM

All replies

  • If I recall correctly I don't think the wdLine property works with a range command. You don't get an error but it just doesn't work.  To pickup that last line you could either change the range to a selection and then move the start position or use something like this.

    Dim rng as Word.Range 'place rng in last line of table cell rng.Bookmarks("\line").Range.Text

    If you use this method, you'll have to trim off the end of cell marker.

     


    Kind Regards, Rich ... http://greatcirclelearning.com

    • Marked as answer by orlandp Wednesday, March 14, 2012 1:42 AM
    Tuesday, March 13, 2012 12:52 PM
  • You are right, wdLine property does not work, but MoveStartUntil did.  Thanks.
    Wednesday, March 14, 2012 1:42 AM