Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Jun 2002
    Location
    Durham, North Carolina, USA
    Posts
    140
    Thanks
    5
    Thanked 1 Time in 1 Post

    Delete only hidden bookmarks (Word XP)

    Howdy folks,

    My document is crashing repeatedly (out of memory, Word will not be able to undo these changes, etc.), and our local support guy says it's because my Word TOC has created hundreds of hidden bookmarks. Sure enough, I checked, and if anything he was being conservative.

    I already have code written that deletes all the bookmarks in my document. But this document has a lot of bookmarks I need. Does anyone have some code which will delete only the hidden bookmarks?

    TIA,

    Beej

  2. #2
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete only hidden bookmarks (Word XP)

    <pre>Sub DeleteHiddenBookmarks()
    Dim k As Integer
    Dim doc As Document
    Dim bShowHiddenBookmarks As Boolean

    Set doc = ActiveDocument

    bShowHiddenBookmarks = doc.Bookmarks.ShowHidden
    doc.Bookmarks.ShowHidden = True

    For k = doc.Bookmarks.count To 1 Step -1
    If InStr(doc.Bookmarks(k).Name, "_") = 1 Then
    doc.Bookmarks(k).Delete
    End If
    Next k
    doc.Bookmarks.ShowHidden = bShowHiddenBookmarks
    End Sub
    </pre>


    Hope this helps!

  3. #3
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Delete only hidden bookmarks (Word XP)

    This Macro will delete all hidden bookmarks, but it will break any cross references to headings, numbered items etc.

    StuartR

    <code>
    Sub DelHiddenBookmarks()
    Dim blShowHidden As Boolean
    Dim i As Integer

    blShowHidden = ActiveDocument.Bookmarks.ShowHidden
    If Not blShowHidden Then ActiveDocument.Bookmarks.ShowHidden = True

    For i = ActiveDocument.Bookmarks.Count To 1 Step -1
    If Left(ActiveDocument.Bookmarks(i).Name, 1) = "_" Then
    ActiveDocument.Bookmarks(i).Delete
    End If
    Next i

    If Not blShowHidden Then ActiveDocument.Bookmarks.ShowHidden = False
    End Sub
    </code>

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Delete only hidden bookmarks (Word XP)

    I guess that goes to show that, other than stylistic differences, there's only one sensible way to do the job <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

    StuartR

  5. #5
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Delete only hidden bookmarks (Word XP)

    Beej

    You could also try this one. I got it from a Ms KB article but cannot find the reference

    Sub StripHiddenBookmarks()
    Dim i As Long

    ActiveDocument.Bookmarks.ShowHidden = True

    For i = ActiveDocument.Bookmarks.Count To 1 Step -1

    If Left$(ActiveDocument.Bookmarks(i).Name, 4) = "_Toc" Then
    ActiveDocument.Bookmarks(i).Delete
    End If

    Application.ActiveDocument.UndoClear

    Next i

    ActiveDocument.Bookmarks.ShowHidden = False

    End Sub

    Worked fine for me using MSO 2003
    cheers

    Phil Carter

  6. #6
    4 Star Lounger
    Join Date
    Feb 2002
    Location
    Auckland, New Zealand
    Posts
    543
    Thanks
    56
    Thanked 0 Times in 0 Posts

    Re: Delete only hidden bookmarks (Word XP)

    Hi again Beej

    I found the link I referred to in my previous

    http://support.microsoft.com/kb/q240410/
    cheers

    Phil Carter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •