首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改评论的作者

问更改评论的作者
EN

Stack Overflow用户
提问于 2022-06-29 22:07:29
回答 2查看 237关注 0票数 1

我有一张桌子上的单词列表。我有一个VBA单词宏来读取这个表。当宏标识表中的单词时,它会添加注释或建议。例如:“不要用那个词”。当前,这些注释的作者默认为运行宏的人的名称。如果用户John运行宏,则显示每个注释,标签为"John“作为作者。我怎样才能把作者改成“机器人”?我添加了comment.author行,但它不起作用。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-07-13 22:08:42

解决办法是将注释的作者更改为“机器人”:

  1. 在所有注释的作者名称后面添加"_0“。
  2. Process将新的_0注释添加到author =”机器人“。以"_0“结尾的作者的评论保持原样。

代码语言:javascript
复制
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
票数 0
EN

Stack Overflow用户

发布于 2022-06-30 07:05:50

您必须为创建的注释设置作者。

用这支潜艇

代码语言:javascript
复制
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

您必须将代码段更改为:

代码语言:javascript
复制
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 while
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72808367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档