Moving backwards one character

S

Stephen English

I have a bookmark near the end of a document and just before it I have a
Pagebreak which I want to delete
ActiveDocument.Bookmarks("Finish").Select
Please how do I move backwards one or two characters so that I can delete it.
I know it is simple but I am having a mental block!
Thanks
Stephen
 
H

Helmut Weber

Hi Stephen,

like this:

Selection.Characters.First.Previous.Delete

Better use range, however.
 
J

JCNZ

This will deal with any number of characters before the page break:

Sub PBDel()
With Selection
.GoTo what:=wdGoToBookmark, Name:="Finish"
Do
.MoveUp unit:=wdLine, Count:=1, Extend:=wdExtend
Loop Until Asc(Selection) = 12
.Delete
End With
End Sub

- but you'll need to add an error handler if you aren't sure that there will
always be a page break.
 
J

Jean-Guy Marcil

JCNZ was telling us:
JCNZ nous racontait que :
This will deal with any number of characters before the page break:

Sub PBDel()
With Selection
.GoTo what:=wdGoToBookmark, Name:="Finish"
Do
.MoveUp unit:=wdLine, Count:=1, Extend:=wdExtend
Loop Until Asc(Selection) = 12
.Delete
End With
End Sub

- but you'll need to add an error handler if you aren't sure that
there will always be a page break.

Yes, but this deletes everything between the page break and the bookmark, I
thin the user wanted to delete the page break that precedes the bookmark.
But I may be wrong as the question was not all that clearly expressed.
If that is the case, try this:

Dim rgeDelete As Range

Set rgeDelete = ActiveDocument.Bookmarks("Finish").Range

With rgeDelete
.MoveStartUntil Chr(12), wdBackward
.MoveStart wdCharacter, -1
.Collapse wdCollapseStart
.Delete
End With

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top