Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

range.delete in Word

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
US
Here's an odd one. I'm trying to remove spaces at the end of paragraphs, using the following code:
Code:
     erng.StartOf wdStory
     erng.Find.Execute " ^p"
     Do While erng.Find.found
        erng.Collapse wdCollapseStart
        erng.MoveEnd , 1
        erng.MoveStartWhile " ", wdBackward
        erng.Delete
        erng.Find.Execute
     Loop
The code seems to work well up to the erng.delete statement. If a single space at the end of the line is selected (I verify this by going in debug mode and executing erng.select from the immediate window), the erng.delete method does NOT delete the space - it just collapses the erng range. In just about any other situation, the range.delete method works as expected, deleting the desired range of text. Am I missing something?
Rob
 
By the way, it's easy to find a workaround, for example:
Code:
     erng.StartOf wdStory
     erng.Find.Execute " ^p"
     Do While erng.Find.found
        erng.Collapse wdCollapseStart
        j = -erng.MoveWhile(" ", wdBackward)
        erng.Delete , j + 1
        erng.Find.Execute
     Loop
But I'm still curious why the delete method didn't work.
Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top