ActiveDocument.Bookmarks: Accessing, Adding, Deleting & Looping Through Bookmarks in Word VBA
ActiveDocument.Bookmarks is a collection object that represents all the bookmarks in the active document. It allows you to access and manipulate individual bookmarks within the document.\n\nHere are a few common operations that can be performed using ActiveDocument.Bookmarks:\n\n1. Accessing a specific bookmark: You can access a specific bookmark by using its name or index. For example, you can use ActiveDocument.Bookmarks("BookmarkName") or ActiveDocument.Bookmarks(1) to access the first bookmark in the collection.\n\n2. Adding a new bookmark: You can add a new bookmark to the document using the Add method of the Bookmarks collection. For example, ActiveDocument.Bookmarks.Add "NewBookmark", Range:=Selection.Range.\n\n3. Deleting a bookmark: You can delete a bookmark from the document using the Delete method of the Bookmarks collection. For example, ActiveDocument.Bookmarks("BookmarkName").Delete.\n\n4. Checking if a bookmark exists: You can check if a bookmark exists in the document by using the Exists method of the Bookmarks collection. For example, ActiveDocument.Bookmarks.Exists("BookmarkName").\n\n5. Looping through all bookmarks: You can use a For Each loop to iterate through all the bookmarks in the collection. For example, \n\nVBA\nDim bm As Bookmark\nFor Each bm In ActiveDocument.Bookmarks\n ' Do something with each bookmark\nNext bm\n\n\nThese are just a few examples of what you can do with ActiveDocument.Bookmarks. The collection provides many other methods and properties that can be used to manipulate bookmarks in a Word document.
原文地址: https://www.cveoy.top/t/topic/pxXB 著作权归作者所有。请勿转载和采集!