2
votes

I have a simple Word macro to add a new comment on selected text:

Dim cmtMyComment As Comment
Set cmtMyComment = Comments.Add(Selection.range, "abc")

Debug.Print cmtMyComment.Index & ". " & Selection.range.Start & " - " & Selection.range.End
Debug.Print cmtMyComment.range.Start & " - " & cmtMyComment.range.End

and Word Document with a lot of comments on one page:

enter image description here

After I select some text at bottom of the page and run this macro, it works well. My comment is added as the last with comment text "abc" and comment index 38.

Debug output:

38. 1099 - 1107
1265 - 1268

When I right click on text-range of last comment and choose "Edit comment" (=Upravit komentar) it shows window to edit the comment.

After closing the Edit window I'm trying to select new text at the bottom and run my macro. The new comment is added at the selected position, but with no text - it's just a empty comment. Text of the comment is appended to the first comment of the page. So now each new comment is empty and text is appended to beginning of the first comment (comment index is now 1).

Debug output:

1. 1003 - 1011
1 - 17

enter image description here

I have MS Word 2016. Until I add comments without editing one in Edit window my macro works well.

Is there a workaround to add comments after editing one in the Edit window?

1

1 Answers

1
votes

I had a similar thing but it was in with footnotes in 2010.

I suspect it is selecting the text in the comments pane and not the body of the document. Have your macro ensure the revision pane is closed.

ActiveDocument.ActiveWindow.View.SplitSpecial = wdPaneNone

Also prefix Comments with Selection, this will help you debug the issue.

Set cmtMyComment = Selection.Comments.Add(Selection.range, "abc")