Results 1 to 14 of 14
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Remove all bookmarks (Word 2000 SR1)

    I need to remove ALL bookmarks (i.e. including hidden) from a number of documents, lots of bookmarks, lots of documents. As far as I can see, bookmarks can only be deleted one at a time. Somebody please tell me there's an easier way!

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

    Re: Remove all bookmarks (Word 2000 SR1)

    This short macro should do the trick...

    StuartR


    Sub DeleteBookmarks()
    Dim bmkTemp As Bookmark
    Dim blWasHidden As Boolean

    blWasHidden = ActiveDocument.Bookmarks.ShowHidden
    ActiveDocument.Bookmarks.ShowHidden = True

    For Each bmkTemp In ActiveDocument.Bookmarks
    bmkTemp.Delete
    Next bmkTemp

    ActiveDocument.Bookmarks.ShowHidden = blWasHidden

    End Sub

  3. #3
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Remove all bookmarks (Word 2000 SR1)

    Many thanks. The task was getting very boring!

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Remove all bookmarks (Word 2000 SR1)

    Hi Peter,

    Be careful that you don't destroy the integrity of your documents by deleting all bookmarks - if you're not careful you might accidentally wipe out TOCs, cross-references etc along the way too.

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. #5
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Remove all bookmarks (Word 2000 SR1)

    Thanks for adding this warning.
    On this occasion, I do want to destroy the TOC, cross references etc prior to converting the document to HTML in Word. Then I run it through HTML Kit (an excellent free editor) that has a function to remove all Word's proprietory code and leave me with clean HTML code. None of the links are required in the HTML and it's easier to remove them in Word first than it is to remove them from the HTML code.
    For others though in different circumstances, adding your warning to this thread might save them from disaster. I appreciate your thought.

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove all bookmarks (Word 2000 SR1)

    Hi Peter:
    I'm not a VBA expert by any means, but I think this macro will delete all bookmarks except the hidden ones:<pre>Sub BookmarksRemoveAll()
    ' from Allen Wyatt Word Tips
    ' removes all bookmarks from document
    Dim objBookmark As Bookmark
    For Each objBookmark In ActiveDocument.Bookmarks
    objBookmark.Delete
    Next
    End Sub</pre>


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

    Re: Remove all bookmarks (Word 2000 SR1)

    Phil,

    Your macro will remove all bookmarks that are currently visible. If the user has set hidden bookmarks to be visible then they would be deleted, otherwise they will not.

    StuartR

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove all bookmarks (Word 2000 SR1)

    Thanks, Stuart. I hadn't realized that before. I should put a message in the beginning that says to check for that. I tried using:

    "MsgBox (Prompt,[=vbOKCancel]) "Make sure hidden bookmarks are hidden or shown as desired"

    but I'm getting an "Expected end of statement error". <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Remove all bookmarks (Word 2000 SR1)

    If you want to provide the user with an escape route, use code like this:

    If MsgBox("Make sure hidden bookmarks are hidden or shown as desired" & vbCrLf & _
    "Do you want to continue?", vbOKCancel Or vbQuestion) = vbCancel Then Exit Sub

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove all bookmarks (Word 2000 SR1)

    Thanks, Hans. It works now.

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

    Re: Remove all bookmarks (Word 2000 SR1)

    If you're going to prompt the user then why not something like...

    Select Case MsgBox(Prompt:="Do you want to delete Hidden Bookmarks as well as normal ones", Buttons:=vbYesNoCancel)
    Case vbYes
    ActiveDocument.Bookmarks.ShowHidden = True
    Case vbNo
    ActiveDocument.Bookmarks.ShowHidden = False
    Case Else
    Exit Sub
    End Select

    StuartR

  12. #12
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove all bookmarks (Word 2000 SR1)

    Thanks, Stuart. It keeps getting better. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  13. #13
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Remove all bookmarks (Word 2000 SR1)

    Thanks to everyone for their input. I was just going to use Stuart's original macro for some one off work. Now I think I will add in the escape route. Then I have a very useful macro for the future with some safety if I forget the danger of the original.
    Thanks again everyone.

  14. #14
    3 Star Lounger
    Join Date
    Feb 2001
    Location
    UK
    Posts
    239
    Thanks
    4
    Thanked 1 Time in 1 Post

    Re: Remove all bookmarks (Word 2000 SR1)

    In case it is of use to others, I have added below the final code used.

    On running the macro, you first get the options to include or exclude hidden bookmarks or to abort. After the macro has run, you get a message to tell you the bookmarks have been deleted.

    It is working exactly as required so thanks again to everyone.

    THE CODE

    Sub RemoveBookmarks()
    Select Case MsgBox(Prompt:="Do you want to delete hidden bookmarks as well as normal ones?", _
    Buttons:=vbYesNoCancel)
    Case vbYes
    ActiveDocument.Bookmarks.ShowHidden = True
    Case vbNo
    ActiveDocument.Bookmarks.ShowHidden = False
    Case Else
    Exit Sub
    End Select
    Dim objBookmark As Bookmark
    For Each objBookmark In ActiveDocument.Bookmarks
    objBookmark.Delete
    Next
    MsgBox "The bookmarks have been deleted.", vbOKOnly
    End Sub

Posting Permissions

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