VBA Word会在选择中使每3个单词变为粗体

时间:2016-12-13 13:53:05

标签: vba ms-word selection

所以我一直试图在一个特定的选择中用一个单词docuemnt粗制每3个单词,或者如果整个文档中每3个单词没有选择任何单词。我尝试了不同的方法但没有任何效果。

1 个答案:

答案 0 :(得分:1)

我应该说“你到目前为止尝试了什么?”和“让我们看看你的代码。”,但我还没有真正用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
相关问题