我有一张桌子上的单词列表。我有一个VBA单词宏来读取这个表。当宏标识表中的单词时,它会添加注释或建议。例如:“不要用那个词”。当前,这些注释的作者默认为运行宏的人的名称。如果用户John运行宏,则显示每个注释,标签为"John“作为作者。我怎样才能把作者改成“机器人”?我添加了comment.author行,但它不起作用。
Do While .Execute(Forward:=True) = True
suggestion = Documents(DocName).Tables(1).Rows(RowCounter).Cells(CellWithSuggestion).range.Text
ActiveDocument.Comment.Author = "robot"
ActiveDocument.Comments.Add findRange, Text:=suggestion
findRange.Collapse wdCollapseEnd 'to avoid getting into endless loop
Loop 'do while发布于 2022-07-13 22:08:42
解决办法是将注释的作者更改为“机器人”:
Dim brand As String
Dim Comment As Comment
brand = "robot"
If ActiveDocument.Comments.Count > 0 Then
For Each Comment In ActiveDocument.Comments
Comment.Author = Comment.Author & "_0"
Next
End If
If ActiveDocument.Comments.Count > 0 Then
For Each Comment In ActiveDocument.Comments
If InStr(1, Comment.Author, "_0", 1) = 0 Then
Comment.Author = brand
End If
Next
End If发布于 2022-06-30 07:05:50
您必须为创建的注释设置作者。
用这支潜艇
Option Explicit
Private Const SystemAuthorForComments As String = "robot"
Sub addComment(rgComment As Range, strMessage As String, _
Optional ByVal strAuthor As String)
If LenB(strAuthor) = 0 Then strAuthor = SystemAuthorForComments
Dim doc As Word.Document: Set doc = rgComment.Parent
Dim c As Word.Comment
Set c = doc.Comments.Add(rgComment, strMessage)
c.Author = strAuthor
End Sub您必须将代码段更改为:
Do While .Execute(Forward:=True) = True
suggestion = Documents(DocName).Tables(1).Rows(RowCounter).Cells(CellWithSuggestion).Range.Text
addComment findrange, suggestion '--> this is how you call the sub
findrange.Collapse wdCollapseEnd 'to avoid getting into endless loop
Loop 'do whilehttps://stackoverflow.com/questions/72808367
复制相似问题