问题
I'm trying to copy some comments from a .docx file to another, together with all the replies made to those comments. I've remove non essential parts to not confuse you.
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
Everything works except the Replies.Add() part. I get a compile error: Object doesn't support this property or method. I'm not a vba programmer and i seem to have hit a brick wall here.
回答1:
According to MSDN, the Replies.Add
method expects a Range
and an optional Text
as parameters. It cannot be directly be called with a Comment
as parameter.
Example:
Sub AddComment()
Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Comments(1).Replies.Add _
Range:=Selection.Range, Text:="review this"
End Sub
来源:https://stackoverflow.com/questions/38246126/vb-macro-to-copy-word-comments-from-one-doc-to-another