Delete everything after blank bookmark

K

Katherine

My structured document contains a series of bookmarks, and I have a userform
which inserts values into them. After submitting the info from the userform
into the relevant bookmarks, I want to delete the rest of the structured
document (because its possible that only the first 8 or so bookmarks will
actually be needed, depending on the situation - long story, just trust me on
this).

So what I want to do is search for the first empty bookmark and delete
everything in the document after that point.

Any clues?
 
B

Birgit

Hi Katherine,
I do not have time to write code right now, so I hope you will be able to do
with some hints:

Loop through the bookmarks and check if the range of the bookmark is empty.
If this is true then define a range (or if you are more comfortable with
selections: the selection) as beginning at the beginning of the bookmark and
ending at the end of the document.
Delete the range or selection.

HTH
Birgit
 
H

Helmut Weber

Hi,
I do not have time to write code right now,
so I hope you will be able to do
with some hints:
Same with me,
but make sure to cycle through
activedocument.range.bookmarks, not through
activedocument.bookmarks.
The first gives you the bookmarks in linear order
from the docs start.
The second gives you the bookmarks in
alphabetical order.
Not to mention bookmarks in different storyranges.
 
D

Dave Lett

Hi Katherine,

You can only really do this if you have enclosing bookmarks (instead of
placeholder bookmarks).

Dim oBk As Bookmark
Dim oRngDelete As Range
For Each oBk In ActiveDocument.Range.Bookmarks
If oBk.Range.Text = "" Then
Set oRngDelete = ActiveDocument.Range _
(Start:=oBk.Range.Start, _
End:=ActiveDocument.Range.End)
oRngDelete.delete
End If
Next oBk

HTH,
Dave
 

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