我在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
为每条评论指定不同作者的代码 - 如果在“评论”>“跟踪更改”>“跟踪更改选项”>选择作者的评论中,则会产生不同的颜色编码评论:
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
答案 0 :(得分:2)
是的,可以在创建Comment
后为Add
设置其他属性,因为Comments的Comment
方法返回对新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
对象的引用。这意味着您可以一次完成颜色编码。我稍微修改了你的代码,如下所示:
{{1}}