Delete all bookmarks (well nearly all)

T

Toby

I have a large document template that contains many bookmarks which are used,
deleted etc. by various procedures. At the very end of the procedures I want
to delete all bookmarks (which is no problem) except for about 6 that I have
to leave in place.

I cannot figure out how to refer to a bookmark by name in an if statement to
restrict the delete loop. The following still deletes ALL bookmarks.

Dim bookmark as Variant
For Each bookmark in ActiveDocument.Bookmarks
If bookmark<>"TC"
ActiveDocument.Bookmarks(bookmark).Delete
End If
Next

Thanks
Toby
 
G

Greg

Here is an example of code that deletes all bookmarks except the one
named "Keep_Me"

Sub ScratchMacro()
Dim oBkm As bookmark
For Each oBkm In ActiveDocument.Range.Bookmarks
If oBkm.Name <> "Keep_Me" Then
oBkm.Delete
End If
Next
End Sub

You might also be interested in my Bookmark Tool.

http://gregmaxey.mvps.org/Bookmark_Tool.htm
 

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