delete text within a range

R

red6000

Hi,

If I have 2 bookmarks in a document named 'a' and 'b' what code would I need
to delete everything in between these 2 bookmarks?

Thanks for your help.
 
H

Helmut Weber

Hi,

With ActiveDocument
.Range(.Bookmarks("A").End, .Bookmarks("B").start).Delete
End With

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

Jonathan West

Helmut Weber said:
Hi,

With ActiveDocument
.Range(.Bookmarks("A").End, .Bookmarks("B").start).Delete
End With

Not quite.

With ActiveDocument
.Range(.Bookmarks("A").Range.End, .Bookmarks("B").Range.Start).Delete
End With

or if you want to delete from the text including the bookmarks

With ActiveDocument
.Range(.Bookmarks("A").Range.Start, .Bookmarks("B").Range.End).Delete
End With

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi Jonathan,

sure you have a reason for using .Bookmarks("A").range.start
instead of .Bookmarks("A").start.

But what could that be?

I tried both ways and it seems either one works.

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

Jonathan West

Helmut Weber said:
Hi Jonathan,

sure you have a reason for using .Bookmarks("A").range.start
instead of .Bookmarks("A").start.

But what could that be?

I tried both ways and it seems either one works.


Ah. I hadn't noticed that bookmarks have a Start and End property. I had
always worked with the range property. I live & learn!


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.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