Hack 37 Delete All Bookmarks in a DocumentWord 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 troublefor 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 Insert 4.12.1 The Code
Place this macro in the template of your choice [Hack #50]
and either run it from the Tools 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 4.12.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 Insert 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 |