[英]Highlight All Bookmarks in Word Doc Via VBA
I want to highlight all the bookmarks in my Word document. 我想突出显示我的Word文档中的所有书签。 When I try to show the bookmarks, I only get the "I".
当我尝试显示书签时,只会显示“ I”。 And this code doesn't do anything.
此代码不执行任何操作。
Just like one of the commentators wrote, my bookmarks are 0 length. 就像其中一位评论员所写的一样,我的书签的长度为0。 But even then how can I highlight say 2 spaces forward?
但是即使如此,我该如何突出显示向前2个空格?
Sub BookMarks2Bold()
Dim bm As Bookmark
Dim tx As Range
Set tx = ActiveDocument.StoryRanges(wdMainTextStory)
For Each bm In tx.Bookmarks
bm.Range.HighlightColorIndex = wdYellow
Next
End Sub 结束子
If your bookmarks are zero range and you still want to highlight something in the document, you can extend the bookmark range, eg be the following character in the document: 如果您的书签的范围是零,而您仍要突出显示文档中的某些内容,则可以扩展书签的范围,例如在文档中使用以下字符:
Sub BookMarks2Bold()
Dim bm As Bookmark
Dim tx As Range
dim rng as Range
Set tx = ActiveDocument.StoryRanges(wdMainTextStory)
For Each bm In tx.Bookmarks
set rng = bm.Range
rng.MoveEnd wdCharacter ' extend by one character
' optionally, expand by one word
' rng.Expand wdWord
rng.HighlightColorIndex = wdYellow
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.