Delete text between two bookmarks

G

Greg G

Can some one help me out with the VBA coding that will enable me to
delete the text between 2 bookmarks?

For example:

{Text1} Just a test {Text2}

I want to delete between Text1 & Text2.

There was another posting regarding defining "Just a test" as a
bookmark and just selecting and deleting that bookmark. My document is
well established and redefining bookmarks would be too time consuming.
Thanks for your help in advance.

Greg
 
G

Greg G

I figured it out this afternoon after some hacking and piecing together
different responses elsewhere on the board.

Dim pRange
Dim dRange
Dim myrange

pRange = ActiveDocument.Bookmarks("Text1").Range.Start
dRange = ActiveDocument.Bookmarks("Text2").Range.End
Set myrange = ActiveDocument.Range(Start:=pRange, End:=dRange)
myrange.Cut

If anyone has something better, please do not hesitate to respond.
Thanks
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Dim myrange as Range
Set myrange = ActiveDocument.Bookmarks("Text1").Range
myrange.End = ActiveDocument.Bookmarks("Text2").Range.End
myrange.Delete

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

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