VBA Word 在选择中每 3 个单词加粗
VBA Word make every 3 words' bold in a selection
所以我一直在尝试在特定选择中将单词文档中的每 3 个单词设为粗体,或者如果整个文档中每 3 个单词没有选中任何内容。我尝试了不同的方法,但没有任何效果。
我应该说 "What have you tried so far?" 和 "Lets see your code.",但我还没有真正用 Word 编码所以我想试试看....
这似乎可以解决问题,尽管可能有更好的编码方式:
Public Sub BoldText()
Dim wrd As Range
Dim x As Long
Dim doc As Variant
If Selection.Start = Selection.End Then
Set doc = ThisDocument
Else
Set doc = Selection
End If
x = 0
For Each wrd In doc.Words
x = x + 1
If x Mod 3 = 0 Then
wrd.Bold = True
End If
Next wrd
End Sub
所以我一直在尝试在特定选择中将单词文档中的每 3 个单词设为粗体,或者如果整个文档中每 3 个单词没有选中任何内容。我尝试了不同的方法,但没有任何效果。
我应该说 "What have you tried so far?" 和 "Lets see your code.",但我还没有真正用 Word 编码所以我想试试看....
这似乎可以解决问题,尽管可能有更好的编码方式:
Public Sub BoldText()
Dim wrd As Range
Dim x As Long
Dim doc As Variant
If Selection.Start = Selection.End Then
Set doc = ThisDocument
Else
Set doc = Selection
End If
x = 0
For Each wrd In doc.Words
x = x + 1
If x Mod 3 = 0 Then
wrd.Bold = True
End If
Next wrd
End Sub