April 5, 2011, 1:59 p.m.
posted by francis
Delete All Bookmarks in a Document
Word offers no built-in way to delete all of a document's bookmarks at once. This hack shows you how to do it with some VBA.
Bookmarks let you quickly navigate through a document. But if you will eventually import your document into another program, such as Quark or FrameMaker, those bookmarks can cause trouble—for example, FrameMaker attempts to convert some bookmarks into its own similar "marker" feature, but it often creates unresolved cross-references that you must delete. Conversely, when exporting to Word format from another program, the program may create bookmarks of questionable value in the Word document.
You can select InsertBookmark and delete bookmarks one at a time, but if a document has dozens or more, you'll be clicking for a while. The macro in this hack will delete them all at once.
1 The Code
The following macro deletes every bookmark in a document:
Sub DeleteAllBookmarks( ) Dim i As Integer For i = ActiveDocument.Bookmarks.Count To 1 Step -1 ActiveDocument.Bookmarks(i).Delete Next i End Sub
2 Hacking the Hack
Word hides some of the bookmarks it creates, such as the ones for cross-references, by default. A hidden bookmark isn't included when iterating through each bookmark in a document, unless the "Hidden bookmarks" box in the InsertBookmark dialog is checked. To be sure you get all of them, this version of the macro turns on that setting before running:
Sub DeleteAllBookmarksIncludingHidden( ) Dim i As Integer Activedocument.Bookmarks.ShowHidden = True For i = ActiveDocument.Bookmarks.Count To 1 Step -1 ActiveDocument.Bookmarks(i).Delete Next i End Sub