Joanne was telling us:
Joanne nous racontait que :
> I wrote the following code to get rid of extraneous characters at the
> end of a document. Once I get the "Move Start" working correctly, I
[quoted text clipped - 5 lines]
> it passes the "Like" line, it jumps out of the while loop. I can't
> see what I'm doing wrong. Thanks so much for your help.
Try this:
'_______________________________________
Sub FixEndSemis()
Dim rng As Range
Set rng = ActiveDocument.Range
With rng
.Collapse wdCollapseEnd
While .Characters.First Like "[!A-z]"
.MoveStart Unit:=wdCharacter, Count:=-1
Wend
.MoveStart Unit:=wdCharacter, Count:=1
.Delete
End With
End Sub
'_______________________________________
Here is how I see the problem with your code: (By the way, it has nothing to
do with the "2" digit...)
> Sub FixEndSemis()
> Dim rng As Range
> Set rng = ActiveDocument.Range
> With rng
> .Collapse wdCollapseEnd
Select the last character in the document
> .MoveStart Unit:=wdCharacter, Count:=-1
Make sure it non-alphabetic, by the way, I think you can use A-z
> While .Text Like "[!A-Za-z]"
If it isn't, select he preceding character
> .MoveStart Unit:=wdCharacter, Count:=-1
> '.Select
Go back to the begining of the loop
> Wend
This is the problem, now you have 2 characters that you are trying to match
to a single string pattern. Of course it does not match and the loop is
exited.
> End With
At least, this is how I understand it. SO my code compares one character at
the time.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org