ActiveDocumentBookmarks
In the context of Microsoft Word, "ActiveDocument.Bookmarks" refers to a property that allows you to access and manipulate the bookmarks within the currently active document.
Bookmarks in Word are used to mark specific locations or ranges of text within a document for future reference or for programming purposes. The "ActiveDocument.Bookmarks" property provides a way to programmatically interact with these bookmarks.
For example, you can use the "ActiveDocument.Bookmarks.Add" method to create a new bookmark at a specific location in the document. You can also use the "ActiveDocument.Bookmarks.Item" method to access a specific bookmark by its name or index. Once you have accessed a bookmark, you can modify its properties, such as the name, range, or visibility.
Here is an example of how to use the "ActiveDocument.Bookmarks" property to add a new bookmark and modify its properties:
Sub AddBookmark()
Dim doc As Document
Set doc = ActiveDocument
' Add a new bookmark at the current selection
doc.Bookmarks.Add Name:="MyBookmark", Range:=Selection.Range
' Access the newly added bookmark and modify its properties
Dim bookmark As Bookmark
Set bookmark = doc.Bookmarks("MyBookmark")
bookmark.Name = "NewName" ' Change the bookmark name
bookmark.Range.Bold = True ' Apply bold formatting to the bookmark range
bookmark.Visible = False ' Hide the bookmark
' Save the changes and close the document
doc.Save
doc.Close
End Sub
This example demonstrates how to create a new bookmark at the current selection, access it using the "ActiveDocument.Bookmarks" property, and modify its properties as needed
原文地址: https://www.cveoy.top/t/topic/hOTf 著作权归作者所有。请勿转载和采集!