我试图将.docx文件中的一些注释复制到另一个文件,以及对这些注释所做的所有回复。我删除了非必要的部分,以免混淆你。
Dim sourceDoc As Word.Document
Dim targetDoc As Word.Document
Set sourceDoc = GetObject("E:\tests\src.docx")
Set targetDoc = GetObject("E:\tests\dest.docx")
For Each comment In sourceDoc.Comments
text = comment.Scope.text
comment.Scope.Select
Set range = targetDoc.range(comment.Scope.Start, comment.Scope.End)
range.Expand (wdParagraph) ' Paragraphs(1).range
range.Select
f.Execute FindText:=text
Set newComment = Selection.Comments.Add(range:=Selection.range)
newComment.range.FormattedText = comment.range.FormattedText
newComment.Author = comment.Author
newComment.Initial = comment.Initial
For i = 1 To comment.Replies.Count
newComment.Replies.Add (comment.Replies(i))
Next i
Next comment
除Replies.Add()部分外,一切正常。我收到编译错误:对象不支持此属性或方法。我不是一个vba程序员,我似乎在这里打了一堵砖。
答案 0 :(得分:1)
根据MSDN,Replies.Add
方法需要Range
和可选的Text
作为参数。不能使用Comment
作为参数直接调用它。
示例:
Sub AddComment()
Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Comments(1).Replies.Add _
Range:=Selection.Range, Text:="review this"
End Sub