VB Macro to copy word comments from one doc to another

佐手、 提交于 2020-01-05 03:37:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!