Remove certain bookmarks

M

MarkN

I have many documents containing lots of bookmarks. Many of these bookmarks
are no longer required and I want to remove all bookmarks with names that
contain "_LINK". Is this something that can be done or is this going to be a
long day??
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?TWFya04=?=,
I have many documents containing lots of bookmarks. Many of these bookmarks
are no longer required and I want to remove all bookmarks with names that
contain "_LINK". Is this something that can be done or is this going to be a
long day??
Shouldn't be a huge problem. Here's a bit of code, off the top of my head:

Sub RemoveLINKBookmarks()
Dim doc As Word.Document
Dim bkm As Word.Bookmark
Dim aBKM() As String
Dim counter As Long

Set doc = ActiveDocument
counter = 0
ReDim aBKM(doc.Bookmarks.Count)
For Each bkm In doc.Bookmarks
If InStr(bkm.Name, "_LINK") <> 0 Then
aBKM(counter) = bkm.Name
counter = counter + 1
End If
Next
For counter = LBound(aBKM()) To UBound(aBKM())
If Len(aBKM(counter)) > 0 Then
doc.Bookmarks(aBKM(counter)).Delete
End If
Next
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
B

Bear

Cindy:

As I see it your strategy here is to crate an array containing the names of
the _LINK bookmarks. Then you go through the array, find all the nonzero
members, and use those to delete the offending bookmarks by index.

But why can't you For Each through the bookmarks collection and delete those
bookmarks on the spot?

I'm not trying to be lazy here. I'm sure if I tried the experiment the way I
described it there would be some problem, and that's why you've done it the
way you've done it.

I'm just wondering if you can explain the underlying mechanics that require
your approach?

Bear
 

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