Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

Moving backwards one character

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stephen English - 11 Oct 2006 04:27 GMT
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
Helmut Weber - 11 Oct 2006 08:28 GMT
Hi Stephen,

like this:

Selection.Characters.First.Previous.Delete

Better use range, however.

Signature

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000 (german versions)

JCNZ - 21 Oct 2006 01:35 GMT
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.

> I have a bookmark near the end of a document and just before it I have a
> Pagebreak which I want to delete
[quoted text clipped - 3 lines]
> Thanks
> Stephen
Jean-Guy Marcil - 21 Oct 2006 05:42 GMT
JCNZ was telling us:
JCNZ nous racontait que :

> This will deal with any number of characters before the page break:
>
[quoted text clipped - 10 lines]
> - 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

Signature

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

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.