How to Reply to a Comment in Word in C#, VB.NET

2017-04-26 07:31:01 Written by  support iceblue
Rate this item
(0 votes)

In Word 2013 and later version, you can reply to a comment, so it's easier to follow the whole conversation. Spire.Doc also allows programmers to insert a comment as a reply to a selected comment through ReplyToComment method.

Step 1: Create an object of Document and load a Word document containing comments.

Document doc = new Document();
doc.LoadFromFile("Comment.docx");

Step 2: Get the first comment.

Comment comment = doc.Comments[0];

Step 3: Create a new comment and specify the author and content.

Comment replyComment = new Comment(doc);
replyComment.Format.Author = "Adam";
replyComment.Body.AddParagraph().AppendText("Exactly.");

Step 4: Add the new comment as a reply to the selected comment.

comment.ReplyToComment(replyComment);

Step 5: Save to file.

doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);

How to Reply to a Comment in Word in C#, VB.NET

Full Code:

[C#]
using Spire.Doc;
using Spire.Doc.Fields;
namespace ReplyComment
{
    class Program
    {

        static void Main(string[] args)
        {

            Document doc = new Document();
            doc.LoadFromFile("Comment.docx");
            Comment comment = doc.Comments[0];

            Comment replyComment = new Comment(doc);
            replyComment.Format.Author = "Adam";
            replyComment.Body.AddParagraph().AppendText("Exactly.");
            comment.ReplyToComment(replyComment);

            doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013);

        }
    }
}
[VB.NET]
Imports Spire.Doc
Imports Spire.Doc.Fields
Namespace ReplyComment
	Class Program

		Private Shared Sub Main(args As String())

			Dim doc As New Document()
			doc.LoadFromFile("Comment.docx")
			Dim comment As Comment = doc.Comments(0)

			Dim replyComment As New Comment(doc)
			replyComment.Format.Author = "Adam"
			replyComment.Body.AddParagraph().AppendText("Exactly.")
			comment.ReplyToComment(replyComment)

			doc.SaveToFile("ReplyToComment.docx", FileFormat.Docx2013)

		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title: Reply to a Comment in Word in C#, VB.NET
Last modified on Friday, 03 September 2021 03:50