Clear text after a bookmark

Clear text after a bookmark

Post by Colin Telf » Sun, 25 Mar 2007 17:26:47


can anybody help me with some code for MS word 2003. I want to clear the
text / characters/ numbers after a bookmark leaving the bookmark intact.

.Bookmarks("Fax_no").Select
Selection.MoveRight Unit:=wdCharacter, Count:=15, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1

this is the code i have sussed out so far, the only thing is it deletes the
line and the bookmark which i don't wish to do.

Can anybody help?



Cheers
Colin
 
 
 

Clear text after a bookmark

Post by Doug Robbi » Sun, 25 Mar 2007 17:56:56

Use:

Dim frange As Range
With ActiveDocument
Set frange = .Bookmarks("Fax_no").Range
frange.Collapse wdCollapseEnd
frange.End = .Range.End
frange.Delete
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

 
 
 

Clear text after a bookmark

Post by Greg Maxe » Sun, 25 Mar 2007 22:31:39

Doug,

Colin posted this question earlier in another group. I create a
bookmark named Fax_num in the middle of a document. If I run this
code, it deletes all the text after the bookmark leaving the bookmark
and everything before it untouched just like your suggested code does:

Sub Scratchmacro()
Dim oRng As Word.Range
Set oRng = ActiveDocument.Range
oRng.Start = ActiveDocument.Bookmarks("Fax_num").Range.End
oRng.Delete
End Sub

He replie back by e-mail "That it works, the only thing is it deletes
the text and bookmark as well" I simply don't see how that is
possible.



On Mar 24, 4:56 am, "Doug Robbins - Word MVP"
 
 
 

Clear text after a bookmark

Post by Doug Robbi » Mon, 26 Mar 2007 01:05:09

Hi Greg,

Neither your nor my code deletes the bookmark.

--
Regards,

Doug Robbins - Word MVP