2

我在 Word 2007 中有一个用户表单,用于搜索文档中的特定术语并添加评论。对于这些评论,我有三个不同的类别。我希望为每个类别对评论进行颜色编码。目前我有一个可行的解决方案,但速度很慢。在创建评论时,是否有另一种方法可以直接指定评论作者?

评论创建代码:

For i = 0 To UBound(CritArray)
    PosCount = 1
    With Selection
    .HomeKey wdStory
        With .Find
        .ClearFormatting
            Do While .Execute(FindText:=CritArray(i), _
            Forward:=True, _
            MatchWholeWord:=True)
Select Case i
...
End Select
            PosCount = PosCount + 1

            Selection.Comments.Add _
            Range:=Selection.Range, _
            Text:=MessArray(i) & CritArray(i) & "' - found for the" & Str(FoundCount) & ". time"

            Loop

        End With
    End With
Next

为每个评论分配不同作者的代码 - 如果在 Review>Track Changes>Track Changes Options>Comments by author 下被选中,这将导致不同颜色编码的评论:

Dim CurrentExpField As String

For Each objCom In ActiveDocument.Comments

    CurrentExpField = Left$(objCom.Range.Text, 3)
    objCom.Author = UCase(CurrentExpField)
    objCom.Initial = UCase(CurrentExpField)

Next
4

1 回答 1

4

是的,因为Comments 的方法返回对新对象的引用,Comment所以可以在创建 a 后为其设置其他属性。这意味着您可以一次完成颜色编码。我稍微修改了您的代码以执行此操作,如下所示:AddComment

Dim cmtMyComment as Comment

For i = 0 To UBound(CritArray)
    PosCount = 1
    With Selection
    .HomeKey wdStory
        With .Find
        .ClearFormatting
            Do While .Execute(FindText:=CritArray(i), _
            Forward:=True, _
            MatchWholeWord:=True)
Select Case i
...
End Select
            PosCount = PosCount + 1

            Set cmtMyComment = Selection.Comments.Add(Range:=Selection.Range, _
            Text:=MessArray(i) & CritArray(i) & "' - found for the" & Str(FoundCount) & ". time")

            cmtMyComment.Author = UCase(Left$(cmtMyComment.Range.Text, 3))
            cmtMyComment.Initial = UCase(Left$(cmtMyComment.Range.Text, 3))

            Loop

        End With
    End With
Next
于 2011-03-18T20:47:15.490 回答