Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2007

Tip: Looking for answers? Try searching our database.

Remove certain bookmarks

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MarkN - 20 Jul 2006 05:30 GMT
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??
Signature

Any help appreciated,
MarkN

Cindy M  -WordMVP- - 20 Jul 2006 09:54 GMT
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 :-)
MarkN - 21 Jul 2006 00:50 GMT
Thanks Cindy,
The 'off the top of your head' code worked like a charm.
Signature

Thanks again,
MarkN

> Hi =?Utf-8?B?TWFya04=?=,
>
[quoted text clipped - 34 lines]
> This reply is posted in the Newsgroup; please post any follow question or reply
> in the newsgroup and not by e-mail :-)
Bear - 09 Mar 2007 14:51 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.