1
我试图从一个.docx文件复制一些评论到另一个,连同对这些评论所做的所有答复。我删除了非必要的部分,以免混淆你。VB将宏从一个文档复制到另一个文档的宏
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程序员,我似乎在这里遇到了一堵砖墙。
我不是很熟悉这个属性,但你不应该声明newComment作为评论对象 –
它是在我已经删除了部分中声明。它自己的评论是复制文件。问题似乎是调用Add newComment.Replies。 –
你在什么版本的Word? 'Comment.Replies'仅在Word 2013中可用。 –